Skip to content

file in node: ReferenceError: done is not defined when filename evaluation fails #5928

Closed

Description

@codeCraft-Ritik

Current Behavior

When a file in node fails to evaluate its filename property (e.g. when configured with a dynamic JSONata expression, an invalid environment variable, or a non-existent context reference), the node throws an unhandled:

ReferenceError: done is not defined
    at @node-red/nodes/core/storage/10-file.js:317:28
    at Object.evaluateNodeProperty (@node-red/util/lib/util.js)

This occurs because in packages/node_modules/@node-red/nodes/core/storage/10-file.js at line 302, the input callback is defined as function(msg, nodeSend, nodeDone). However, at line 317 inside the error handler of RED.util.evaluateNodeProperty, it calls return done(); instead of return nodeDone();.
This uncaught ReferenceError terminates message processing abnormally and crashes the flow execution.

Expected Behavior

When property evaluation for the filename fails, the file in node should report the error via node.error(err, msg) and cleanly complete message handling by invoking nodeDone(), without throwing a ReferenceError.

Steps To Reproduce

  1. Add a file in node to a flow.
  2. Set the Filename property type to JSONata expression and use an expression that produces an evaluation error, such as $undefinedFunction().
  3. Send an input message to the node.
  4. Observe that instead of gracefully handling the error and calling nodeDone(), the runtime throws an uncaught ReferenceError: done is not defined at 10-file.js:317.

Example flow

```json
[
    {
        "id": "tab_file_in_repro",
        "type": "tab",
        "label": "Repro: file in ReferenceError",
        "disabled": false,
        "info": ""
    },
    {
        "id": "inject_trigger",
        "type": "inject",
        "z": "tab_file_in_repro",
        "name": "Trigger File Read",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 140,
        "wires": [
            [
                "file_in_bad_filename"
            ]
        ]
    },
    {
        "id": "file_in_bad_filename",
        "type": "file in",
        "z": "tab_file_in_repro",
        "name": "Read file (bad JSONata filename)",
        "filename": "$nonExistentFunction()",
        "filenameType": "jsonata",
        "format": "utf8",
        "chunk": false,
        "sendError": true,
        "encoding": "none",
        "allProps": false,
        "x": 450,
        "y": 140,
        "wires": [
            [
                "debug_result"
            ]
        ]
    },
    {
        "id": "debug_result",
        "type": "debug",
        "z": "tab_file_in_repro",
        "name": "Output",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 140,
        "wires": []
    },
    {
        "id": "catch_errors",
        "type": "catch",
        "z": "tab_file_in_repro",
        "name": "Catch Errors",
        "scope": null,
        "uncaught": false,
        "x": 170,
        "y": 220,
        "wires": [
            [
                "debug_error_out"
            ]
        ]
    },
    {
        "id": "debug_error_out",
        "type": "debug",
        "z": "tab_file_in_repro",
        "name": "Caught Error",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "error",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 420,
        "y": 220,
        "wires": []
    }
]

paste your flow here



### Environment


- Node-RED version: 5.0.6 (and all prior versions with 3-arg input signature)
- Node.js version: v18.x / v20.x / v22.x / v24.x
- npm version: 10.x / 11.x
- Platform/OS: Windows / Linux / macOS
- Browser: N/A (Core storage node)

Activity

  1. R0CKing666 commented on Sep 8, 2026

    @R0CKing666
    Contributor

    I reproduced this on Node-RED 5.0.6 and submitted a fix with a regression test in #5931.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions