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

Restore File In node behaviour of sending msg on error

This commit is contained in:
Nick O'Leary 2017-07-04 19:55:09 +01:00
parent f7bb4a7d60
commit 47e2707fd3
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 26 additions and 12 deletions

View File

@ -172,7 +172,11 @@ module.exports = function(RED) {
}
})
.on('error', function(err) {
node.error('Error while reading file.', msg);
node.error(err, msg);
var sendMessage = RED.util.cloneMessage(msg);
delete sendMessage.payload;
sendMessage.error = err;
node.send(sendMessage);
})
.on('end', function() {
if (node.chunk === false) {

View File

@ -495,10 +495,18 @@ describe('file Nodes', function() {
});
it('should handle a file read error', function(done) {
var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", "filename":"badfile", "format":""}];
var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", "filename":"badfile", "format":"", wires:[["n2"]]},
{id:"n2", type:"helper"}
];
helper.load(fileNode, flow, function() {
var n1 = helper.getNode("fileInNode1");
setTimeout(function() {
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.not.have.property('payload');
msg.should.have.property("error");
msg.error.should.have.property("code","ENOENT");
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "file in";
});
@ -506,10 +514,12 @@ describe('file Nodes', function() {
logEvents[0][0].should.have.a.property('msg');
logEvents[0][0].msg.toString().should.startWith("Error");
done();
},wait);
} catch(err) {
done(err);
}
});
n1.receive({payload:""});
});
});
});
});