Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Node: TypeError: Cannot read property 'name' of undefined #933

Closed
DeanCording opened this issue Jul 8, 2016 · 1 comment
Closed

Comments

@DeanCording
Copy link

DeanCording commented Jul 8, 2016

There is a case where the debug node will throw TypeError: Cannot read property 'name' of undefined

A test case involves the httpInMultipart node:

[ {
    "id": "499fe21f.f66814",
    "type": "httpInMultipart",
    "z": "c8dc8a91.74103",
    "name": "OTA Firmware",
    "url": "/esp8266-ota/upload",
    "method": "post",
    "fields": "[{ \"name\": \"firmware\"}]",
    "swaggerDoc": "",
    "x": 155.5,
    "y": 811,
    "wires": [
        [
            "eeb8fd90.56a408",
            "ff8b5370.8bcc78"
        ]
    ]
},
{
    "id": "ff8b5370.8bcc78",
    "type": "debug",
    "z": "c8dc8a91.74103",
    "name": "files",
    "active": true,
    "console": "true",
    "complete": "req.files",
    "x": 735.5,
    "y": 800,
    "wires": []
}
]

The debug node is set to display msg.req.files which is an array of objects containing the files received.

In debug.js, the error is thrown at:

  function sendDebug(msg) {
     ....
     msg.format = msg.msg.constructor.name || "Object";

msg.msg is the output, in this case msg.req.files (Note: the name msg refers to different objects)

msg.req.files.constructor is 'undefined' and therefore does not have a property 'name' - javascript throws an exception rather than return 'undefined' like it would for a defined object.

@DeanCording
Copy link
Author

Fix:

        try {
            msg.format = msg.msg.constructor.name;
        } catch (e) {
            msg.format = "Object";
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant