From 0d9abbb8b635fc51520100ad532afcb9643610c5 Mon Sep 17 00:00:00 2001 From: Mark Hindess Date: Thu, 9 Oct 2014 11:19:14 +0100 Subject: [PATCH] Minor fixes to messages sent from "file in" nodes. Specifically: * in the error case, set msg.filename to be the name of the file used (as is done in the non-error case), * in the error case, delete msg.payload so that subsequent nodes only need check for a msg.payload to act upon if they don't care about error cases, and * in the non-error case, delete msg.error to avoid passing through errors from earlier nodes to a subsequent node that does care about error cases Messages sent will now always have well-defined behaviour with respect to the payload, filename, and error in both error and non-error cases. --- nodes/core/storage/50-file.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nodes/core/storage/50-file.js b/nodes/core/storage/50-file.js index d6cc4410d..b9cb7953f 100644 --- a/nodes/core/storage/50-file.js +++ b/nodes/core/storage/50-file.js @@ -76,13 +76,15 @@ module.exports = function(RED) { if (filename === "") { node.warn('No filename specified'); } else { + msg.filename = filename; fs.readFile(filename,options,function(err,data) { if (err) { node.warn(err); msg.error = err; + delete msg.payload; } else { - msg.filename = filename; msg.payload = data; + delete msg.error; } node.send(msg); });