From 811aa2301069f300d0ab9be5305d00a2a0cbfab7 Mon Sep 17 00:00:00 2001 From: nome Date: Mon, 4 Apr 2016 13:46:48 +0200 Subject: [PATCH] Include tiddler line number in SyntaxError output While JavaScript runtime errors include the line number within the module tiddler where the error occured, syntax errors do not, leaving the user guessing where the error is hiding. Attempt to remedy this, as well as the various platforms permit. --- boot/boot.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/boot/boot.js b/boot/boot.js index 7d3df8af6..0bf28bef0 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -712,7 +712,24 @@ $tw.modules.execute = function(moduleName,moduleRoot) { moduleInfo.exports = moduleInfo.definition; } } catch(e) { - $tw.utils.error("Error executing boot module " + name + ":\n" + e.stack); + if (e instanceof SyntaxError) { + var line = e.lineNumber || e.line; // Firefox || Safari + if (typeof(line) != "undefined" && line !== null) { + $tw.utils.error("Syntax error in boot module " + name + ":" + line + ":\n" + e.stack); + } else if(!$tw.browser) { + // this is the only way to get node.js to display the line at which the syntax error appeared, + // and $tw.utils.error would exit anyway + // cf. https://bugs.chromium.org/p/v8/issues/detail?id=2589 + throw e; + } else { + // Opera: line number is included in e.message + // Chrome/IE: there's currently no way to get the line number + $tw.utils.error("Syntax error in boot module " + name + ": " + e.message + "\n" + e.stack); + } + } else { + // line number should be included in e.stack for runtime errors + $tw.utils.error("Error executing boot module " + name + ": " + JSON.stringify(e) + "\n\n" + e.stack); + } } } // Return the exports of the module