1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 05:19:57 +00:00

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.
This commit is contained in:
nome 2016-04-04 13:46:48 +02:00 committed by Jeremy Ruston
parent 9e01a30dc7
commit 811aa23010

View File

@ -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