From fa4b646fcbc0d3f04d44be6b9e885dad7a197e82 Mon Sep 17 00:00:00 2001 From: "Francois (fge)" Date: Mon, 1 Mar 2021 16:24:53 +0000 Subject: [PATCH] [FIX] web: traceback issue in firefox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/web/static/src/js/core/error_utils.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/web/static/src/js/core/error_utils.js b/addons/web/static/src/js/core/error_utils.js index 2ccfb5cd6db..1c3e14fa01c 100644 --- a/addons/web/static/src/js/core/error_utils.js +++ b/addons/web/static/src/js/core/error_utils.js @@ -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() === "") {