Skip to content
Snippets Groups Projects
Commit 2716828f authored by Géry Debongnie's avatar Géry Debongnie
Browse files

[IMP] web: display better tracebacks in debug=assets


The recent change in the way debug=assets works (which now bundles all
files in a bundle instead of serving them statically) had a negative
impact on the stacktrace displayed in the error dialog in debug=assets:
it now display the bundle/linenumber instead of the actual file/line
number.

This is not a huge deal, most of the time, because the errors displayed
in the console display the correct information, and the debugging
process should work as before.  But it can certainly be annoying in some
cases.

With this commit, we use the Stacktrace.js library to dynamically fetch
the sourcemaps and to decorate the displayed information with the
correct file and line numbers.

closes odoo/odoo#66318

Signed-off-by: default avatarAaron Bohy (aab) <aab@odoo.com>
parent 1bd73558
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ odoo.define('base_automation.BaseAutomatioErrorDialogTests', function (require)
const CrashManager = require('web.CrashManager').CrashManager;
const session = require('web.session');
const makeTestEnvironment = require("web.test_env");
QUnit.module('base_automation', {}, function () {
......@@ -32,6 +33,7 @@ odoo.define('base_automation.BaseAutomatioErrorDialogTests', function (require)
session.is_admin = true;
let crashManager = new CrashManager();
crashManager.env = makeTestEnvironment();
let dialog = crashManager.show_error(error);
await dialog._opened;
......@@ -56,6 +58,7 @@ odoo.define('base_automation.BaseAutomatioErrorDialogTests', function (require)
},
};
let crashManager = new CrashManager();
crashManager.env = makeTestEnvironment();
let dialog = crashManager.show_error(error);
await dialog._opened;
......
Copyright (c) 2017 Eric Wendelin and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -16,6 +16,7 @@ var core = require('web.core');
var Dialog = require('web.Dialog');
var ErrorDialogRegistry = require('web.ErrorDialogRegistry');
var Widget = require('web.Widget');
var config = require('web.config');
var _t = core._t;
var _lt = core._lt;
......@@ -36,6 +37,7 @@ var CrashManagerDialog = Dialog.extend({
xmlDependencies: (Dialog.prototype.xmlDependencies || []).concat(
['/web/static/src/xml/crash_manager.xml']
),
jsLibs: ['/web/static/lib/stacktracejs/stacktrace.js'],
/**
* @param {Object} error
......@@ -46,10 +48,29 @@ var CrashManagerDialog = Dialog.extend({
*/
init: function (parent, options, error) {
this._super.apply(this, [parent, options]);
this.error = error;
this.message = error.message;
this.traceback = error.traceback;
core.bus.off('close_dialogs', this);
},
willStart: async function () {
await this._super(...arguments);
if (config.isDebug('assets') && this.error.data && this.error.data.jsError) {
// annotate the stacktrace with correct file/line number information
const frames = await StackTrace.fromError(this.error.data.jsError);
const lines = this.traceback.split('\n');
if (lines[lines.length-1].trim() === "") {
// firefox traceback have an empty line at the end
lines.splice(-1);
}
const offset = lines.length - frames.length;
for (let i = 0; i < frames.length; i++) {
const info = ` (${frames[i].fileName}:${frames[i].lineNumber})`;
lines[offset + i] = lines[offset + i] + info;
}
this.traceback = lines.join('\n');
}
},
});
var ErrorDialog = CrashManagerDialog.extend({
......@@ -137,7 +158,7 @@ var CrashManager = AbstractService.extend({
self.show_error({
type: _t("Odoo Client Error"),
message: message,
data: {debug: file + ':' + line + "\n" + _t('Traceback:') + "\n" + traceback},
data: {debug: file + ':' + line + "\n" + _t('Traceback:') + "\n" + traceback, jsError: error},
});
}
};
......
......@@ -52,7 +52,8 @@ odoo.define('web.test_env', async function (require) {
ajax: {
rpc() {
return env.session.rpc(...arguments); // Compatibility Legacy Widgets
}
},
loadLibs() {}
},
getCookie() {},
httpRequest(/* route, params = {}, readMethod = 'json' */) {
......
......@@ -635,6 +635,7 @@
<script type="text/javascript" src="/web/static/lib/Chart/Chart.js"></script>
<script type="text/javascript" src="/web/static/lib/nearest/jquery.nearest.js"/>
<script type="text/javascript" src="/web/static/lib/daterangepicker/daterangepicker.js"></script>
<script type="text/javascript" src="/web/static/lib/stacktracejs/stacktrace.js"></script>
<script type="text/javascript" src="/web/static/src/js/libs/daterangepicker.js"></script>
<script type="text/javascript" src="/web/static/tests/main_tests.js"></script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment