diff options
| author | Mohammed Shekha <msh@odoo.com> | 2020-08-21 09:46:34 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2020-08-21 14:33:45 +0000 |
| commit | 1ca3a590f7399f1379eea02c83eaa6046856a795 (patch) | |
| tree | 264e2f0b49f1ba7b6b68a1a0fdf3aa3598b6fb0b /addons/web/static/src/js/services | |
| parent | 6a5ee406d81513e20baf1bdd610ca56c8348d6ec (diff) | |
[FIX] web: crash manager correctly formats error message in Firefox
Have a piece of code that throws an Error
In browsers not powered by V8, the stack trace won't be formatted and the Error
type won't appear in the crash manager modal report.
This happens because Error.prototype.stack is non-standard, although most
browsers have an implementation of it. Chrome for example automatically formats
the Error.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
https://v8.dev/docs/stack-trace-api\#compatibility
After this commit, the Error is formatted in the crash manager report, the same
way as Chrome does it.
task-2191727
closes odoo/odoo#56318
X-original-commit: dbf670f2e0ec797aeaf998aa28b32afbdd2c3b4c
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Co-authored-by: Lucas Perais <lpe@odoo.com>
Co-authored-by: Hardik Prajapati <hap@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/services')
| -rw-r--r-- | addons/web/static/src/js/services/crash_manager.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/addons/web/static/src/js/services/crash_manager.js b/addons/web/static/src/js/services/crash_manager.js index cb7e5c3b054..65e15df59ea 100644 --- a/addons/web/static/src/js/services/crash_manager.js +++ b/addons/web/static/src/js/services/crash_manager.js @@ -27,6 +27,14 @@ window.addEventListener('unhandledrejection', ev => let active = true; +// Note: we already have this function in browser_detection.js but browser_detection.js +// is in assets_backend while crash_managere.js is in common so it will have dependency +// of file browser_detection.js which will not be available in frontend, so copy function here +const isBrowserChrome = function () { + return $.browser.chrome && // depends on jquery 1.x, removed in jquery 2 and above + navigator.userAgent.toLocaleLowerCase().indexOf('edge') === -1; // as far as jquery is concerned, Edge is chrome +}; + /** * An extension of Dialog Widget to render the warnings and errors on the website. * Extend it with your template of choice like ErrorDialog/WarningDialog @@ -141,7 +149,17 @@ var CrashManager = AbstractService.extend({ // promise has been rejected due to a crash core.bus.on('crash_manager_unhandledrejection', this, function (ev) { if (ev.reason && ev.reason instanceof Error) { - var traceback = ev.reason.stack; + // Error.prototype.stack is non-standard. + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error + // However, most engines provide an implementation. + // In particular, Chrome formats the contents of Error.stack + // https://v8.dev/docs/stack-trace-api#compatibility + let traceback; + if (isBrowserChrome()) { + traceback = ev.reason.stack; + } else { + traceback = `${_t("Error:")} ${ev.reason.message}\n${ev.reason.stack}`; + } self.show_error({ type: _t("Odoo Client Error"), message: '', |
