File in node - throws error and provides payload with error message

In case of an error (file not found) it throws an error and send a payload with msg.error.
According to node help that should not be the case. In addition I cant find the "node configuration"

Node help says:

Legacy error handling

Before Node-RED 0.17, if this node hit an error whilst reading the file, it would send a message with no msg.payload and msg.error set to the details of the error. This is a deprecated mode of behaviour for the node that new instances will not do. If required, this mode can be re-enabled within the node configuration.

Errors should be caught and handled using a Catch node.

The configuration is set in the dialog that opens when you double click the node


As a deprecated option it was removed in the 1.0 release -

Unfortunately the help text wasn't updated to match so it still refers to it.

I have just tested the node and if it tries to read a file that doesn't exist it does not send a message from its output and will log an error that can be handled with the Catch node.

I still get both messages: msg.error and the thrown error.

The change node only sets msg.filename to "bluepages", a name that does not exist.
Even if a type in the filename in the file in node I get the same results.

NodeRED 1.04

If you add a catch node, it will 'catch' the error.
@knolleary without the catch node you do get a error in the debug sidebar and it comes from the file in node:

3/9/2020, 8:21:07 AM[node: 557db1a1.29c118]
msg : error
"Error: ENOENT: no such file or directory, open 'fubar'" 

here is a sample flow (without the catch node) showing the error.

[{"id":"557db1a1.29c118","type":"file in","z":"ee5050c9.d834d8","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":480,"y":300,"wires":[["85dc888f.65dd4"]]},{"id":"f387088c.13a5d","type":"inject","z":"ee5050c9.d834d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":300,"wires":[["de1d29ba.f1fca"]]},{"id":"85dc888f.65dd4","type":"debug","z":"ee5050c9.d834d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":300,"wires":[]},{"id":"de1d29ba.f1fca","type":"change","z":"ee5050c9.d834d8","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"fubar","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":300,"wires":[["557db1a1.29c118"]]}]

@zenofmud yes - that is how it is supposed to work. However, oddly, the screenshot shows that not only the error logged but a message also arrived at the Debug node - that bit we would not expect to see.

@hklages Is this a newly added File node or one you have from a previous version of Node-RED? Can you export your flow and share it here (make sure you format it as a code block using the </> button in the formatting toolbar).

1 Like

Ahh - good hint.

The file in node is "old". After deleting the old node and replacing it by a new one it works as expected. The configuration dialog is now also different. A field "encoding" shows up.

Are there other nodes I have to "replace" after upgrading to 1.0.x?


None that I can think of.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.