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

**URL:** <https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809>\
**Category:** Core Development\
**Created:** [8 March 2020 18:58 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809 "2020-03-08T18:58:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hklages](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hklages/32/23899_2.png) [@hklages](https://discourse.nodered.org/u/hklages)\
**Post date:** [8 March 2020 18:58 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/1 "2020-03-08T18:58:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 March 2020 20:08 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/2 "2020-03-08T20:08:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hklages](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hklages/32/23899_2.png) [@hklages](https://discourse.nodered.org/u/hklages)\
**Post date:** [9 March 2020 10:23 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/3 "2020-03-09T10:23:32Z")

</div>

Where?

 ![fileIn](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce887753211f408b6bbc8355643a5c175c55a18e.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [9 March 2020 10:33 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/4 "2020-03-09T10:33:02Z")

</div>

As a deprecated option it was removed in the 1.0 release - [https://github.com/node-red/node-red/commit/6b61fa9f6f190d954b0b84321d68a1932aabb518#diff-c2df8be4f2f04a21f3e2c6a28d2ff03e](https://github.com/node-red/node-red/commit/6b61fa9f6f190d954b0b84321d68a1932aabb518#diff-c2df8be4f2f04a21f3e2c6a28d2ff03e)

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.

---

<div class="post-metadata">

**Author:** ![hklages](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hklages/32/23899_2.png) [@hklages](https://discourse.nodered.org/u/hklages)\
**Post date:** [9 March 2020 12:10 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/5 "2020-03-09T12:10:39Z")

</div>

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

Example:  
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

 ![error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e3f5ec56141c6b99e04722057e89b4f08dfbd6a2.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 March 2020 12:26 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/6 "2020-03-09T12:26:52Z")

</div>

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:

```auto
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.

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [9 March 2020 12:30 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/7 "2020-03-09T12:30:25Z")

</div>

@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).

---

<div class="post-metadata">

**Author:** ![hklages](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hklages/32/23899_2.png) [@hklages](https://discourse.nodered.org/u/hklages)\
**Post date:** [9 March 2020 12:43 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/8 "2020-03-09T12:43:54Z")

</div>

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?

Thanks.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [9 March 2020 13:21 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/9 "2020-03-09T13:21:56Z")

</div>

> [@hklages](#):
>
> Are there other nodes I have to "replace" after upgrading to 1.0.x?

None that I can think of.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 May 2020 13:22 UTC](https://discourse.nodered.org/t/file-in-node-throws-error-and-provides-payload-with-error-message/22809/10 "2020-05-08T13:22:02Z")

</div>

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