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

undefined key causes Node-RED crash #31

Open
rcarmo opened this issue Dec 26, 2018 · 1 comment
Open

undefined key causes Node-RED crash #31

rcarmo opened this issue Dec 26, 2018 · 1 comment

Comments

@rcarmo
Copy link

rcarmo commented Dec 26, 2018

I'm coming across a situation where the node should report an error without crashing the entire Node-RED process:

TypeError: Cannot read property 'sendEvent' of undefined

This happens when I don't have a SharedKey defined for the connection and undefined gets passed to the node:

26 Dec 14:43:11 - [info] [azureiothub:Stream IoT Hub] Connected to Azure IoT Hub.
26 Dec 14:43:11 - [info] [azureiothub:Stream IoT Hub] Message is pending. Sending it to Azure IoT Hub.
26 Dec 14:43:11 - [info] [azureiothub:Stream IoT Hub] Sending Message to Azure IoT Hub :
   Payload: "{\"battery\":99,\"voltage\":3005,\"linkquality\":0,\"angle_x\":3,\"angle_y\":1,\"angle_z\":87,\"angle_x_absolute\":87,\"angle_y_absolute\":89,\"unknown_data\":3932160,\"action\":\"vibration\"}"
26 Dec 14:43:11 - [info] [filter:filter for STB IP] nr-regexp-filter: message dropped (not matching the '192.168.1.66' regular expression)
26 Dec 14:43:11 - [info] [azureiothub:Stream IoT Hub] Message sent.
26 Dec 14:43:12 - [info] [azureiothub:Stream IoT Hub] JSON
26 Dec 14:43:12 - [info] [azureiothub:Stream IoT Hub] Connection to IoT Hub not established or configuration changed. Reconnecting.
26 Dec 14:43:12 - [info] [azureiothub:Stream IoT Hub] Disconnecting from Azure IoT Hub
26 Dec 14:43:12 - [info] [azureiothub:Stream IoT Hub] Connecting to Azure IoT Hub:
   Protocol: mqtt
   Connection string :HostName=stream.azure-devices.net;DeviceId=router0;SharedAccessKey=undefined
26 Dec 14:43:12 - [error] [azureiothub:Stream IoT Hub] Could not connect: Connection refused: Not authorized
26 Dec 14:43:12 - [info] [azureiothub:Stream IoT Hub] Connected to Azure IoT Hub.
26 Dec 14:43:12 - [info] [azureiothub:Stream IoT Hub] Message is pending. Sending it to Azure IoT Hub.
26 Dec 14:43:12 - [info] [azureiothub:Stream IoT Hub] Sending Message to Azure IoT Hub :
   Payload: "{\"state\":true,\"linkquality\":0,\"description\":\"0/REDACTED\",\"type\":\"COORD\",\"rssi\":1}"
26 Dec 14:43:12 - [red] Uncaught Exception:
26 Dec 14:43:12 - TypeError: Cannot read property 'sendEvent' of undefined
    at sendData (/home/user/.npm-packages/lib/node_modules/node-red-contrib-azure-iot-hub/azureiothub.js:38:16)
    at /home/user/.npm-packages/lib/node_modules/node-red-contrib-azure-iot-hub/azureiothub.js:86:21
    at /home/user/.npm-packages/lib/node_modules/node-red-contrib-azure-iot-hub/node_modules/azure-iot-device/lib/client.js:240:9
    at Mqtt.<anonymous> (/home/user/.npm-packages/lib/node_modules/node-red-contrib-azure-iot-hub/node_modules/azure-iot-device-mqtt/lib/mqtt.js:45:17)
    at MqttClient.errCallback (/home/user/.npm-packages/lib/node_modules/node-red-contrib-azure-iot-hub/node_modules/azure-iot-mqtt-base/lib/mqtt.js:75:7)
    at emitNone (events.js:111:20)
    at MqttClient.emit (events.js:208:7)
    at TLSSocket.f (/home/user/.npm-packages/lib/node_modules/node-red-contrib-azure-iot-hub/node_modules/once/once.js:25:25)
    at TLSSocket.onfinish (/home/user/.npm-packages/lib/node_modules/node-red-contrib-azure-iot-hub/node_modules/end-of-stream/index.js:30:27)
    at emitNone (events.js:111:20)
    at TLSSocket.emit (events.js:208:7)
    at finishMaybe (_stream_writable.js:613:14)
    at stream._final (_stream_writable.js:591:5)
    at TLSSocket.Socket._final (net.js:300:5)
    at callFinal (_stream_writable.js:584:10)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
26 Dec 14:43:27 - [info] 
@Bacto
Copy link

Bacto commented Dec 18, 2020

Hi,

I got the same problem today:

18 Dec 11:45:46 - [error] [azureiothub:Azure IoT Hub] Could not connect: Connection refused: Not authorized
18 Dec 11:45:46 - [red] Uncaught Exception:
18 Dec 11:45:46 - TypeError: Cannot read property 'sendEvent' of undefined
    at sendData (/persistent/storage/node_modules/node-red-contrib-azure-iot-hub/azureiothub.js:38:16)
    at /persistent/storage/node_modules/node-red-contrib-azure-iot-hub/azureiothub.js:86:21
    at /persistent/storage/node_modules/azure-iot-device/lib/client.js:240:9
    at Mqtt.<anonymous> (/persistent/storage/node_modules/azure-iot-device-mqtt/lib/mqtt.js:45:17)
    at MqttClient.errCallback (/persistent/storage/node_modules/azure-iot-mqtt-base/lib/mqtt.js:75:7)
    at MqttClient.emit (events.js:327:22)
    at TLSSocket.f (/persistent/storage/node_modules/once/once.js:25:25)
    at TLSSocket.onfinish (/persistent/storage/node_modules/end-of-stream/index.js:31:27)
    at TLSSocket.emit (events.js:315:20)
    at finishMaybe (_stream_writable.js:639:14)
    at ShutdownWrap.callback (_stream_writable.js:616:5)
    at ShutdownWrap.afterShutdown [as oncomplete] (net.js:432:8)

It seems the node doesn't catch errors like it should (see https://nodered.org/docs/user-guide/handling-errors#uncatchable-errors).

The problem is that Node-RED quits because of this error.

Is it something that can be fixed?

Thanks,
Adrien

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

2 participants