Make buildmessage parseStack more robust to multi-line errors.

This makes Handlebars parse errors not crash.
This commit is contained in:
David Glasser
2013-07-02 19:50:38 -07:00
parent a753284c6d
commit 12a93615cf

View File

@@ -239,13 +239,10 @@ var jobHasMessages = function () {
// If a function on the stack has been marked with markBoundary, don't
// return anything past that function. We call this the "user portion"
// of the stack.
//
// XXX This will blow up on errors whose message contains
// newlines. Might want to be more robust to that.
var parseStack = function (err) {
var frames = err.stack.split('\n');
frames.shift(); // first line is the exception
frames.shift(); // at least the first line is the exception
var stop = false;
var ret = [];
@@ -274,8 +271,12 @@ var parseStack = function (err) {
line: m[3] ? +m[3] : undefined,
column: m[5] ? +m[5] : undefined
});
} else
} else if (_.isEmpty(ret)) {
// We haven't found any stack frames, so probably we have newlines in the
// error message. Just skip this line.
} else {
throw new Error("Couldn't parse stack frame: '" + frame + "'");
}
});
return ret;
@@ -390,4 +391,4 @@ _.extend(exports, {
error: error,
exception: exception,
jobHasMessages: jobHasMessages
});
});