node-red: Unexpected Node Error

Current Behavior

31 Jan 11:30:21 - [error]


Unexpected Node Error TypeError: Cannot read property ‘log’ of undefined at log_helper (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:507:20) at Node.error (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:538:9) Node: Type: undefined Module: undefined ID: undefined Properties: ArrayBuffer[f] Array[f] Atomics[o] BigInt64Array[f] BigInt[f] BigUint64Array[f] Buffer[f] DataView[f] Date[f] Error[f] EvalError[f] Float32Array[f] Function[f] GLOBAL[o] Infinity[n] Int16Array[f] Int32Array[f] Int8Array[f] JSON[o] Map[f] Math[o] NaN[n] Number[f] Object[f] Promise[f] Proxy[f] ReferenceError[f] Reflect[o] RegExp[f] Set[f] SharedArrayBuffer[f] String[f] SyntaxError[f] TextDecoder[f] TextEncoder[f] TypeError[f] URIError[f] URL[f] Uint16Array[f] Uint32Array[f] Uint8Array[f] Uint8ClampedArray[f] WeakSet[f] WebAssembly[o] RESOLVED_TMP_DIR[s] __assign[f] __asyncGenerator[f] __asyncValues[f] __await[f] __awaiter[f] __classPrivateFieldSet[f] core-js_shared[o] __createBinding[f] __decorate[f] __extends[f] __generator[f] __importDefault[f] __importStar[f] __metadata[f] __param[f] __read[f] __rest[f] __spreadArray[f] __spreadArrays[f] __values[f] bcrypt[o] clearImmediate[f] clearInterval[f] clearTimeout[f] constructor[f] decodeURIComponent[f] decodeURI[f] encodeURIComponent[f] escape[f] eval[f] globalThis[o] global[o] hwsHubs[o] isFinite[f] isNaN[f] onConnectionEnd[o] onConnectionError[o] onConnectionSuccess[o] onReceive[o] onResponseTimeOut[o] parseFloat[f] parseInt[f] process[o] root[o] setImmediate[f] setInterval[f] setTimeout[f] undefined[u] unescape[f] Flow: undefined Type: undefined Properties: undefined

Please report this issue, including the information logged above: https://github.com/node-red/node-red/issues/


Expected Behavior

No response

Steps To Reproduce

No response

Example flow

paste your flow here

Environment

  • Node-RED version: 2.2.0
  • Node.js version:
  • npm version:
  • Platform/OS: Raspberry Pi
  • Browser: Chrome

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Happy ending to my story: I upgraded to Node-RED v2.2.1 today (thank you for sneaking this patch in just in time) and was finally able to see the underlying errors. They lead me to suspect network issues and, ultimately, I just had to reseat an ethernet cable of all things. OSI Layer 1 strikes again! @Steve-Mcl I would be glad to buy you a beer or support any initiative you designate with a donation.

@sumoneelse Thanks for the info. I have now managed to re-create the issue.

Not having any TPLink devices, I fired up a simulator (tplink-smarthome-simulator) and re-created the problem.

It lead me to this line in the kasa node.

Essentially, there is an issue with that node whereby the nodes context is being bound to global (as in node globalThis) and therefore causing an error when trying to call expected logging functions from the Node class that are not present.

For example: Current code…

 promise
        .then(info =>
          node.send({
            topic: device.shortId,
            payload: {
              ...info,
              timestamp: moment().format()
            }
          })
        )
        .catch(node.error)

… gives us an error regarding self._flows.log function not found


Improvements for Kasa node…

Changing the kasa nodes code to …

      promise
        .then(info =>
          node.send({
            topic: device.shortId,
            payload: {
              ...info,
              timestamp: moment().format()
            }
          })
        )
        .catch(error => {
          node.error(`Error controlling device: ${error}`)
        })

… now gives the correct error info (a timeout in the TPLink node) and more importantly, doesn’t call the logging function with globalThis context (node is actually/correctly a node-red Node instance)


Improvements for node-red logging of exceptional cases

I have raised PR #3446 which attempts to better capture the real problem.

This is an example of the error output after the PR…

image

which clearly shows the problem emanates from tplink-smarthome-api

I’ve attached a completely fresh 3-node flow which queries a TP-Link Kasa device every 5 seconds and debugs the result. I’ve also attached the debug output (image) which happened to run as follows from launch: success, success, error, success. The error message is right where+when the object should have been returned.

If you were to delete the debug node, you would still see the error in the debug window unattributed to any node. But as the timestamps show, it’s coming in response to a getQuickInfo query to a Kasa node.

error

[ { “id”: “a8f2fd5e9bb60bcf”, “type”: “tab”, “label”: “Flow 1”, “disabled”: false, “info”: “”, “env”: [] }, { “id”: “51cbe3a0c014be3d”, “type”: “inject”, “z”: “a8f2fd5e9bb60bcf”, “name”: “”, “props”: [ { “p”: “payload” } ], “repeat”: “5”, “crontab”: “”, “once”: true, “onceDelay”: 0.1, “topic”: “”, “payload”: “getQuickInfo”, “payloadType”: “str”, “x”: 240, “y”: 140, “wires”: [ [ “8eeec5ba96b67b23” ] ] }, { “id”: “8eeec5ba96b67b23”, “type”: “kasa”, “z”: “a8f2fd5e9bb60bcf”, “name”: “”, “device”: “192.168.150.28”, “interval”: 60000, “eventInterval”: 15000, “payload”: “getInfo”, “payloadType”: “info”, “debug”: false, “x”: 390, “y”: 140, “wires”: [ [ “27a91ca5259df024” ] ] }, { “id”: “27a91ca5259df024”, “type”: “debug”, “z”: “a8f2fd5e9bb60bcf”, “name”: “”, “active”: true, “tosidebar”: true, “console”: false, “tostatus”: false, “complete”: “false”, “statusVal”: “”, “statusType”: “auto”, “x”: 530, “y”: 140, “wires”: [] } ]