mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
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.
This commit is contained in:
parent
da4446c20f
commit
0d9abbb8b6
@ -76,13 +76,15 @@ module.exports = function(RED) {
|
|||||||
if (filename === "") {
|
if (filename === "") {
|
||||||
node.warn('No filename specified');
|
node.warn('No filename specified');
|
||||||
} else {
|
} else {
|
||||||
|
msg.filename = filename;
|
||||||
fs.readFile(filename,options,function(err,data) {
|
fs.readFile(filename,options,function(err,data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
node.warn(err);
|
node.warn(err);
|
||||||
msg.error = err;
|
msg.error = err;
|
||||||
|
delete msg.payload;
|
||||||
} else {
|
} else {
|
||||||
msg.filename = filename;
|
|
||||||
msg.payload = data;
|
msg.payload = data;
|
||||||
|
delete msg.error;
|
||||||
}
|
}
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user