diff --git a/nodes/core/core/80-function.js b/nodes/core/core/80-function.js index d8e236cad..8aa95e4fc 100644 --- a/nodes/core/core/80-function.js +++ b/nodes/core/core/80-function.js @@ -205,10 +205,12 @@ module.exports = function(RED) { var context = vm.createContext(sandbox); try { this.script = vm.createScript(functionText, { - filename: 'Function: '+this.id+(this.name?' ['+this.name+']':''), // filename for stack traces - lineOffset: -11, // line number offset to be used for stack traces - columnOffset: 0, // column number offset to be used for stack traces + filename: 'Function node:'+this.id+(this.name?' ['+this.name+']':''), // filename for stack traces displayErrors: true + // Using the following options causes node 4/6 to not include the line number + // in the stack output. So don't use them. + // lineOffset: -11, // line number offset to be used for stack traces + // columnOffset: 0, // column number offset to be used for stack traces }); this.on("input", function(msg) { try { @@ -224,14 +226,14 @@ module.exports = function(RED) { this.status({fill:"yellow",shape:"dot",text:""+converted}); } } catch(err) { - //remove unwanted part + //remove unwanted part var index = err.stack.search(/\n\s*at ContextifyScript.Script.runInContext/); err.stack = err.stack.slice(0, index).split('\n').slice(0,-1).join('\n'); var stack = err.stack.split(/\r?\n/); //store the error in msg to be used in flows msg.error = err; - + var line = 0; var errorMessage; var stack = err.stack.split(/\r?\n/); diff --git a/test/nodes/core/core/80-function_spec.js b/test/nodes/core/core/80-function_spec.js index 6d5457823..ac48e3c8f 100644 --- a/test/nodes/core/core/80-function_spec.js +++ b/test/nodes/core/core/80-function_spec.js @@ -242,7 +242,7 @@ describe('function node', function() { }); it('should handle and log script error', function(done) { - var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"retunr"}]; + var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"var a = 1;\nretunr"}]; helper.load(functionNode, flow, function() { var n1 = helper.getNode("n1"); n1.receive({payload:"foo",topic: "bar"}); @@ -256,7 +256,7 @@ describe('function node', function() { msg.should.have.property('level', helper.log().ERROR); msg.should.have.property('id', 'n1'); msg.should.have.property('type', 'function'); - msg.should.have.property('msg', 'ReferenceError: retunr is not defined (line 1, col 1)'); + msg.should.have.property('msg', 'ReferenceError: retunr is not defined (line 2, col 1)'); done(); } catch(err) { done(err);