From 47e2707fd35d3a53a2814b51f42f2100f55b1497 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 4 Jul 2017 19:55:09 +0100 Subject: [PATCH] Restore File In node behaviour of sending msg on error --- nodes/core/storage/50-file.js | 6 ++++- test/nodes/core/storage/50-file_spec.js | 32 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/nodes/core/storage/50-file.js b/nodes/core/storage/50-file.js index 34796a109..8e7a71156 100644 --- a/nodes/core/storage/50-file.js +++ b/nodes/core/storage/50-file.js @@ -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) { diff --git a/test/nodes/core/storage/50-file_spec.js b/test/nodes/core/storage/50-file_spec.js index ccc62d734..63bb70a6b 100644 --- a/test/nodes/core/storage/50-file_spec.js +++ b/test/nodes/core/storage/50-file_spec.js @@ -495,21 +495,31 @@ 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 logEvents = helper.log().args.filter(function(evt) { - return evt[0].type == "file in"; - }); - logEvents.should.have.length(1); - logEvents[0][0].should.have.a.property('msg'); - logEvents[0][0].msg.toString().should.startWith("Error"); - done(); - },wait); + 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"; + }); + logEvents.should.have.length(1); + logEvents[0][0].should.have.a.property('msg'); + logEvents[0][0].msg.toString().should.startWith("Error"); + done(); + } catch(err) { + done(err); + } + }); n1.receive({payload:""}); }); }); - }); });