[FIX] web: traceback issue in firefox

In Firefox, the error stack generated by anonymous code (example:
erroneous code in a template) is not compatible with the stacktrace lib.

The error stack could contain lines like :
"anonymous web.assets_common.js line 9786 > Function:442".
In order to make it usable by the stacktrace lib, we will remove
the words "lines", ">", "Function:442" to get:
"anonymous owl.js:1695".

Traceback:

Before:
    Error: QWeb error: Invalid loop expression
        anonymous web.assets_common.js line 9786 > Function:442
        fn owl.js:1567
        render owl.js:1617
        renderFn owl.js:4595
        __render owl.js:4391
        __prepareAndRender owl.js:4379
        __prepare owl.js:4325
        anonymous web.assets_common.js line 9786 > Function:175
        ...

After:
    Error: QWeb error: Invalid loop expression
        anonymous owl.js:1695
        fn owl.js:1567
        render owl.js:1617
        renderFn owl.js:4595
        __render owl.js:4391
        __prepareAndRender owl.js:4379
        __prepare owl.js:4325
        anonymous owl.js:1695
        ...

closes odoo/odoo#67020

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
This commit is contained in:
Francois (fge)
2021-03-02 08:46:07 +00:00
parent 64749aaeaf
commit fa4b646fcb
@@ -37,6 +37,14 @@ export function formatTraceback(error) {
export async function annotateTraceback(error) {
const traceback = formatTraceback(error);
await loadJS('/web/static/lib/stacktracejs/stacktrace.js');
// In Firefox, the error stack generated by anonymous code (example: invalid
// code in a template) is not compatible with the stacktrace lib. This code
// corrects the stack to make it compatible with the lib stacktrace.
if (error.stack) {
const regex = / line (\d*) > (Function):(\d*)/gm;
const subst = `:$1`;
error.stack = error.stack.replace(regex, subst);
}
const frames = await StackTrace.fromError(error);
const lines = traceback.split('\n');
if (lines[lines.length-1].trim() === "") {