tsightler / ring-mqtt

Ring devices to MQTT Bridge
MIT License
569 stars 103 forks source link

Bug: Error message with latest version of dev branch - Cannot read properties of undefined #645

Closed hesral closed 1 year ago

hesral commented 1 year ago

Describe the Bug

Latest version generates an uncaught exception

Steps to Reproduce

install ring-mqtt from dev branch and configure

Expected Behavior

ring-mqtt should start and not generate an error

Log Output

Just tried the dev branch for a fix for the session handling. The initial configuration and startup was fine, however after a reboot, an error was being generated:

2023-05-31T20:05:28.052Z ring-mqtt ERROR - Uncaught Exception
2023-05-31T20:05:28.052Z ring-mqtt Cannot read properties of undefined (reading 'toString')
2023-05-31T20:05:28.053Z ring-mqtt TypeError: Cannot read properties of undefined (reading 'toString')
    at removeTopicAliasAndRecoverTopicName (/app/ring-mqtt/node_modules/mqtt/lib/client.js:150:28)
    at storeAndSend (/app/ring-mqtt/node_modules/mqtt/lib/client.js:222:11)
    at MqttClient._sendPacket (/app/ring-mqtt/node_modules/mqtt/lib/client.js:1240:7)
    at publishProc (/app/ring-mqtt/node_modules/mqtt/lib/client.js:655:14)
    at MqttClient.publish (/app/ring-mqtt/node_modules/mqtt/lib/client.js:665:74)
    at EventEmitter.<anonymous> (file:///app/ring-mqtt/lib/mqtt.js:33:25)
    at EventEmitter.emit (node:events:513:28)
    at Lock.mqttPublish (file:///app/ring-mqtt/devices/base-ring-device.js:225:21)
    at Lock.publishDingState (file:///app/ring-mqtt/devices/intercom.js:86:18)
    at Lock.processDing (file:///app/ring-mqtt/devices/intercom.js:123:14)

Screenshots

No response

Config File

n.a.

Install Type

docker

Version

dev branch

Operating System

Ubuntu

Architecture

x86

Machine Details

physical

tsightler commented 1 year ago

file:///app/ring-mqtt/devices/intercom.js:123:14

This does not appear to be the dev branch. If it were dev the URL would be /app/ring-mqtt-dev/device/intercom.js. You should verify that you have the latest docker image and that you are properly setting the BRANCH environment variable for the dev branch, or are you running this in some other way?

What is really strange is that the error you are seeing is not from ring-mqtt itself, but from the mqtt client library, but it's in code that is 100% untouched from the main branch. Full logs would help.

hesral commented 1 year ago

Hmm, interesting, I tried this docker-compose file:

version: "3.7" services: ring-mqtt: build: https://github.com/tsightler/ring-mqtt.git#dev container_name: ring-mqtt restart: always image: tsightler/ring-mqtt ports:

and ran docker compose build which builded stuff and I assumed was using the dev branch from github for the build.

Logmessage state:

023-05-31T20:06:33.634Z ring-mqtt Cannot read properties of undefined (reading 'toString') 2023-05-31T20:06:33.635Z ring-mqtt TypeError: Cannot read properties of undefined (reading 'toString') at removeTopicAliasAndRecoverTopicName (/app/ring-mqtt/node_modules/mqtt/lib/client.js:150:28) at storeAndSend (/app/ring-mqtt/node_modules/mqtt/lib/client.js:222:11) at MqttClient._sendPacket (/app/ring-mqtt/node_modules/mqtt/lib/client.js:1240:7) at publishProc (/app/ring-mqtt/node_modules/mqtt/lib/client.js:655:14) at MqttClient.publish (/app/ring-mqtt/node_modules/mqtt/lib/client.js:665:74) at EventEmitter. (file:///app/ring-mqtt/lib/mqtt.js:33:25) at EventEmitter.emit (node:events:513:28) at Lock.mqttPublish (file:///app/ring-mqtt/devices/base-ring-device.js:225:21) at Lock.publishDingState (file:///app/ring-mqtt/devices/intercom.js:86:18) at Lock.processDing (file:///app/ring-mqtt/devices/intercom.js:123:14) 2023-05-31T20:06:34.635Z ring-mqtt The ring-mqtt process is shutting down... 2023-05-31T20:06:34.635Z ring-mqtt Setting all devices offline... 2023-05-31T20:06:37.639Z ring-mqtt Exit code: 2

ring-mqtt.js version: 5.3.0 Node version v18.16.0 NPM version 9.1.2 git version 2.38.5

Is 5.3.0 not the current dev branch?

Interestingly the error vanished after an automatic restart of the docker container after this error and the ding properly worked by itself again, thus the setup survived the reboot of the complete machine without the need of reauthentification for the first time since May.

tsightler commented 1 year ago

Well, you don't have to do all of that to test the dev branch. You can just use the standard Docker image for this project and set "BRANCH" environment variable to "dev" during startup (or add it to Docker compose). The image will then automatically pull down latest dev branch on Docker startup. To revert you just remove BRANCH option.

But yes, your method should also work, it's just that I didn't recognize it because of that. Most people just use the BRANCH feature since that makes it super easy.

hesral commented 1 year ago

I've just done another restart of the whole machine. The issue did not occur again in the container setup. Connection was immediately successfull and no exception occured. Maybe it was a weird timing issue during the first try...

tsightler commented 1 year ago

If it repeats, please provide full logs, rather than just the error.