Skip to content

Commit

Permalink
Merge pull request #1374 from stealjs/err-now
Browse files Browse the repository at this point in the history
Prevent removing stack trace when a dependent module throws.
  • Loading branch information
matthewp authored Mar 28, 2018
2 parents 0b62e43 + 0c2c0bf commit db9785b
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 44 deletions.
27 changes: 19 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4297,19 +4297,30 @@ var $__curScript, __eval;

var errArgs = new Error(0, '_').fileName == '_';

function cleanStack(stack, newStack) {
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
}

function addToError(err, msg) {
// parse the stack removing loader code lines for simplification
var newStack = [], stack;
if (!err.originalErr) {
var stack = (err.stack || err.message || err).toString().split('\n');
var newStack = [];
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
stack = (err.stack || err.message || err).toString().split('\n');
cleanStack(stack, newStack);
}

//var newMsg = (newStack ? newStack.join('\n\t') : err.message) + '\n\t' + msg;
var newMsg = err.message + '\n\t' + msg;
if(err.originalErr && !newStack.length) {
stack = err.originalErr.stack.toString().split('\n');
cleanStack(stack, newStack);
}

var newMsg = err.message;
if(!err.onModuleExecution) {
newMsg = err.message + '\n\t' + msg;
}

// Convert file:/// URLs to paths in Node
if (!isBrowser)
Expand Down
27 changes: 19 additions & 8 deletions src/base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2324,19 +2324,30 @@ var $__curScript, __eval;

var errArgs = new Error(0, '_').fileName == '_';

function cleanStack(stack, newStack) {
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
}

function addToError(err, msg) {
// parse the stack removing loader code lines for simplification
var newStack = [], stack;
if (!err.originalErr) {
var stack = (err.stack || err.message || err).toString().split('\n');
var newStack = [];
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
stack = (err.stack || err.message || err).toString().split('\n');
cleanStack(stack, newStack);
}

//var newMsg = (newStack ? newStack.join('\n\t') : err.message) + '\n\t' + msg;
var newMsg = err.message + '\n\t' + msg;
if(err.originalErr && !newStack.length) {
stack = err.originalErr.stack.toString().split('\n');
cleanStack(stack, newStack);
}

var newMsg = err.message;
if(!err.onModuleExecution) {
newMsg = err.message + '\n\t' + msg;
}

// Convert file:/// URLs to paths in Node
if (!isBrowser)
Expand Down
27 changes: 19 additions & 8 deletions src/base/lib/polyfill-wrapper-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,30 @@ var $__curScript, __eval;

var errArgs = new Error(0, '_').fileName == '_';

function cleanStack(stack, newStack) {
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
}

function addToError(err, msg) {
// parse the stack removing loader code lines for simplification
var newStack = [], stack;
if (!err.originalErr) {
var stack = (err.stack || err.message || err).toString().split('\n');
var newStack = [];
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
stack = (err.stack || err.message || err).toString().split('\n');
cleanStack(stack, newStack);
}

//var newMsg = (newStack ? newStack.join('\n\t') : err.message) + '\n\t' + msg;
var newMsg = err.message + '\n\t' + msg;
if(err.originalErr && !newStack.length) {
stack = err.originalErr.stack.toString().split('\n');
cleanStack(stack, newStack);
}

var newMsg = err.message;
if(!err.onModuleExecution) {
newMsg = err.message + '\n\t' + msg;
}

// Convert file:/// URLs to paths in Node
if (!isBrowser)
Expand Down
27 changes: 19 additions & 8 deletions steal-sans-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -4521,19 +4521,30 @@ var $__curScript, __eval;

var errArgs = new Error(0, '_').fileName == '_';

function cleanStack(stack, newStack) {
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
}

function addToError(err, msg) {
// parse the stack removing loader code lines for simplification
var newStack = [], stack;
if (!err.originalErr) {
var stack = (err.stack || err.message || err).toString().split('\n');
var newStack = [];
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
stack = (err.stack || err.message || err).toString().split('\n');
cleanStack(stack, newStack);
}

//var newMsg = (newStack ? newStack.join('\n\t') : err.message) + '\n\t' + msg;
var newMsg = err.message + '\n\t' + msg;
if(err.originalErr && !newStack.length) {
stack = err.originalErr.stack.toString().split('\n');
cleanStack(stack, newStack);
}

var newMsg = err.message;
if(!err.onModuleExecution) {
newMsg = err.message + '\n\t' + msg;
}

// Convert file:/// URLs to paths in Node
if (!isBrowser)
Expand Down
4 changes: 2 additions & 2 deletions steal-sans-promises.production.js

Large diffs are not rendered by default.

27 changes: 19 additions & 8 deletions steal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5791,19 +5791,30 @@ var $__curScript, __eval;

var errArgs = new Error(0, '_').fileName == '_';

function cleanStack(stack, newStack) {
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
}

function addToError(err, msg) {
// parse the stack removing loader code lines for simplification
var newStack = [], stack;
if (!err.originalErr) {
var stack = (err.stack || err.message || err).toString().split('\n');
var newStack = [];
for (var i = 0; i < stack.length; i++) {
if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1)
newStack.push(stack[i]);
}
stack = (err.stack || err.message || err).toString().split('\n');
cleanStack(stack, newStack);
}

//var newMsg = (newStack ? newStack.join('\n\t') : err.message) + '\n\t' + msg;
var newMsg = err.message + '\n\t' + msg;
if(err.originalErr && !newStack.length) {
stack = err.originalErr.stack.toString().split('\n');
cleanStack(stack, newStack);
}

var newMsg = err.message;
if(!err.onModuleExecution) {
newMsg = err.message + '\n\t' + msg;
}

// Convert file:/// URLs to paths in Node
if (!isBrowser)
Expand Down
4 changes: 2 additions & 2 deletions steal.production.js

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions test/init_error/dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>initiation error message</title>
</head>
<body>

<script>
window.assert = window.parent.assert;
window.done = window.parent.done;
</script>
<script src="../../../steal-sans-promises.js"
data-base-url="."
data-config="package.json!npm"></script>
<script>
steal.done().then(null, function(err){
if(window.assert) {
var worked = /two\.js/.test(err.stack) || /Function code/.test(err.stack);
window.assert.ok(worked, "got the source in the stack trace");
window.done();
} else {
console.error(err);
}
});
</script>
</body>
</html>
1 change: 1 addition & 0 deletions test/init_error/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./one");
5 changes: 5 additions & 0 deletions test/init_error/one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var mod = {};

require("./two");

module.exports = mod;
5 changes: 5 additions & 0 deletions test/init_error/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "init-error",
"version": "1.0.0",
"main": "main.js"
}
3 changes: 3 additions & 0 deletions test/init_error/two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {};

throw new Error("Oh no!");
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ QUnit.test("Error message for syntax errors in ES and CJS modules", function(ass
makeIframe("parse_errors/dev.html", assert);
});

QUnit.test("If a module errors because a child module throws show the correct stack trace", function(assert){
makeIframe("init_error/dev.html", assert);
});

QUnit.module("steal startup and config");

QUnit.test("Load urlOptions correctly with async script append", function(assert) {
Expand Down

0 comments on commit db9785b

Please sign in to comment.