1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fixup Function node error line reporting

This commit is contained in:
Nick O'Leary 2018-05-08 11:40:16 +01:00
parent 2fef6fd1fa
commit 98546b6e6a
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 9 additions and 7 deletions

View File

@ -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/);

View File

@ -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);