From bac4beae03e63d3dc0c388c40b687a7bfd104a4a Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sun, 5 Jul 2015 22:40:24 +0100 Subject: [PATCH] Fix Function error parsing for node 0.12 format --- nodes/core/core/80-function.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/nodes/core/core/80-function.js b/nodes/core/core/80-function.js index ce5fdb20a..2f7cb63bd 100644 --- a/nodes/core/core/80-function.js +++ b/nodes/core/core/80-function.js @@ -106,15 +106,27 @@ module.exports = function(RED) { this.status({fill:"yellow",shape:"dot",text:""+converted}); } } catch(err) { - var errorMessage = err.toString(); + + var line = 0; + var errorMessage; var stack = err.stack.split(/\r?\n/); if (stack.length > 0) { - var m = /at undefined:(\d+):(\d+)$/.exec(stack[1]); - if (m) { - var line = Number(m[1])-1; - var cha = m[2]; - errorMessage += " (line "+line+", col "+cha+")"; + while(line < stack.length && stack[line].indexOf("ReferenceError") !== 0) { + line++; } + + if (line < stack.length) { + errorMessage = stack[line]; + var m = /:(\d+):(\d+)$/.exec(stack[line+1]); + if (m) { + var line = Number(m[1])-1; + var cha = m[2]; + errorMessage += " (line "+line+", col "+cha+")"; + } + } + } + if (!errorMessage) { + errorMessage = err.toString(); } this.error(errorMessage, msg); }