From 12a93615cfda92ca7650ffe4d717d92d4877fbf4 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Tue, 2 Jul 2013 19:50:38 -0700 Subject: [PATCH] Make buildmessage parseStack more robust to multi-line errors. This makes Handlebars parse errors not crash. --- tools/buildmessage.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/buildmessage.js b/tools/buildmessage.js index 9b05c5bd37..b8860e6928 100644 --- a/tools/buildmessage.js +++ b/tools/buildmessage.js @@ -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 -}); \ No newline at end of file +});