[FIX] web: avoid translation not ready error in errors

Before this commit, error message like "Uncaught Promise" were
translated. However, it may happen that the error is created (and
thrown) before the translation service is ready, i.e. before the
translations are loaded. Indeed, the error service is started first
and starts listening on errors that might be raised. If a module
throws an error (e.g. rejects a promise) before the localization
service is started, the error service being already set up, it
catches it and instantiates the appropriate Error. Doing so, a
"translation error" is thrown as translations aren't ready yet.

Translating those messages makes little sense anyway, as they
target developpers and they can't be found in the code if they
are translated. This commit thus stop translating them.

Issue found while investigating on opw 3602193

closes odoo/odoo#143551

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Aaron Bohy
2023-11-29 16:30:19 +00:00
parent 7bbba71bda
commit 0dfada3f3f
@@ -1,7 +1,6 @@
/** @odoo-module **/
import { browser } from "../browser/browser";
import { _t } from "@web/core/l10n/translation";
import { registry } from "../registry";
import { completeUncaughtError, getErrorTechnicalName } from "./error_utils";
import { isIOS, isBrowserSafari } from "@web/core/browser/feature_detection";
@@ -23,20 +22,20 @@ export class UncaughtError extends Error {
}
export class UncaughtClientError extends UncaughtError {
constructor(message = _t("Uncaught Javascript Error")) {
constructor(message = "Uncaught Javascript Error") {
super(message);
}
}
export class UncaughtPromiseError extends UncaughtError {
constructor(message = _t("Uncaught Promise")) {
constructor(message = "Uncaught Promise") {
super(message);
this.unhandledRejectionEvent = null;
}
}
export class UncaughtCorsError extends UncaughtError {
constructor(message = _t("Uncaught CORS Error")) {
constructor(message = "Uncaught CORS Error") {
super(message);
}
}
@@ -93,12 +92,11 @@ export const errorService = {
return;
}
uncaughtError = new UncaughtCorsError();
uncaughtError.traceback = _t(
uncaughtError.traceback =
`Unknown CORS error\n\n` +
`An unknown CORS error occured.\n` +
`The error probably originates from a JavaScript file served from a different origin.\n` +
`(Opening your browser console might give you a hint on the error.)`
);
`An unknown CORS error occured.\n` +
`The error probably originates from a JavaScript file served from a different origin.\n` +
`(Opening your browser console might give you a hint on the error.)`;
} else {
uncaughtError = new UncaughtClientError();
uncaughtError.event = ev;