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

unhandled exception now happens after update and crashes Node-Red! #1707

Closed
marc-gist opened this issue Dec 7, 2024 · 14 comments · May be fixed by #1723
Closed

unhandled exception now happens after update and crashes Node-Red! #1707

marc-gist opened this issue Dec 7, 2024 · 14 comments · May be fixed by #1723

Comments

@marc-gist
Copy link

Describe the bug

after upgradding from 0.64 to 0.74.2.

[error] UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#".

To Reproduce

update package to 0.74.2

Expected behavior

to keep running, or throw an error without crashing NR completely.

Screenshots

No response

Example Flow

No response

Environment Information

Version: 0.64.0

Home Assistant instances: 4
Server: 967b6c84.0c1c
Home Assistant version: 2024.1.6
Companion version: 0.0.0
Server: 90fe7859.6f59a8
Home Assistant version: 2024.11.2
Companion version: 4.1.1
Server: 6222af3a.62305
Home Assistant version: 2024.11.3
Companion version: 4.1.1
Server: 6cc6453e51f69328
Home Assistant version: 2024.7.2
Companion version: 0.0.0

Node-RED version: 3.1.14
Docker: yes
Add-on: no

Node.js version: v18.20.4 x64 linux
OS: Linux 6.1.0-20-amd64 x64

Additional context

No response

@marc-gist
Copy link
Author

getting the same issue with v0.69.1
I have even started in safe mode and tried to update all the HA nodes, then start, still getting

[red] Uncaught Exception:
8 Dec 10:48:03 - [error] UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".

@zachowj
Copy link
Owner

zachowj commented Dec 22, 2024

Add the following snippet to your settings.js file to get more detailed information about the rejected promise:

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection: ', p, 'reason:', reason);
});

@ctark
Copy link

ctark commented Dec 24, 2024

Add the following snippet to your settings.js file to get more detailed information about the rejected promise:

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection: ', p, 'reason:', reason);
});

So after adding that to the end of my settings.js, your addon loads but gives this:

24 Dec 10:36:36 - [debug] [server:Home Assistant] States Loaded
24 Dec 10:36:36 - [debug] [server:Home Assistant] Services Loaded
24 Dec 10:36:36 - [debug] [server:Home Assistant] HA State: running
24 Dec 10:36:36 - [debug] [server:Home Assistant] Integration: notloaded
Unhandled Rejection:  Promise {
  <rejected> { code: 'unknown_command', message: 'Unknown command.' }
} reason: { code: 'unknown_command', message: 'Unknown command.' }
Unhandled Rejection:  Promise {
  <rejected> { code: 'unknown_command', message: 'Unknown command.' }
} reason: { code: 'unknown_command', message: 'Unknown command.' }

@marc-gist
Copy link
Author

@ctark you getting the same issue? I don't have time to test adding this to my nodes, as its doing it in my production environment :(
And I don't have a way to test without taking lots of time reloading from backups, back and forth.

@marc-gist
Copy link
Author

Set debug logging and audit true, i get a bit moreinformation...

6 Dec 14:36:10 - [error] UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".

    at throwUnhandledRejectionsMode (node:internal/process/promises:389:7)

    at processPromiseRejections (node:internal/process/promises:470:17)

    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)

I get the same as ctark

Unhandled Rejection:  Promise {

  <rejected> { code: 'unknown_command', message: 'Unknown command.' }

} reason: { code: 'unknown_command', message: 'Unknown command.' }

Unhandled Rejection:  Promise {

  <rejected> { code: 'unknown_command', message: 'Unknown command.' }

} reason: { code: 'unknown_command', message: 'Unknown command.' }

but now NR doesn't crash, which is good.
I also get this in NR GUI, which are two objects, so may give a hint where in your code the issue is

image

Not sure those are related. But find it interesting that I get two Unhandled rejections, and your code is displaying two nodes with issues.

@ctark
Copy link

ctark commented Dec 27, 2024

@ctark you getting the same issue? I don't have time to test adding this to my nodes, as its doing it in my production environment :( And I don't have a way to test without taking lots of time reloading from backups, back and forth.

Yes, started when I updated node red and all nodes to latest. I then got a log entry saying that home assistant needed to be 2023.12 or later (I was pinned to 2023.08 at the time).
Then, when I updated to 2023.12, node red loaded but then crashed due to the above issue.
I have not tried fully updating HA as there are some breaking changes I have to deal with first. The snipped Zachowj suggested stops node red from crashing atleast, so it's good enough for now. I don't have a dev environment so I loose control of the lights in the house when I don't have node red active.

@marc-gist
Copy link
Author

marc-gist commented Dec 28, 2024

Add the following snippet to your settings.js file to get more detailed information about the rejected promise:

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection: ', p, 'reason:', reason);
});

Do you need anything else? @zachowj

@zachowj
Copy link
Owner

zachowj commented Dec 29, 2024

The unhandled exception is caused by Node-RED sending a command over the WebSocket connection that isn’t registered with Home Assistant. This could happen if Node-RED thinks the custom integration is installed when it’s not or if a required component isn’t loaded.

To identify the command sent to Home Assistant, set the logger level for websocket_api to info. You can do this in the Home Assistant configuration or by using the logger.set_level service.

homeassistant.components.websocket_api: info

https://www.home-assistant.io/integrations/logger/

@marc-gist
Copy link
Author

The unhandled exception is caused by Node-RED sending a command over the WebSocket connection that isn’t registered with Home Assistant. This could happen if Node-RED thinks the custom integration is installed when it’s not or if a required component isn’t loaded.

To identify the command sent to Home Assistant, set the logger level for websocket_api to info. You can do this in the Home Assistant configuration or by using the logger.set_level service.

homeassistant.components.websocket_api: info

https://www.home-assistant.io/integrations/logger/

The exception is caused by the Node code not catching exceptions. In my case, looks like it may not be handling errors when entity ids do not exist.

i'll try to do more debugging for you when i have a chance to shutdown my production machine.

Hopefully you have time to check the code for where exceptions are not captured.

Thanks!

@zachowj
Copy link
Owner

zachowj commented Dec 30, 2024

In my case, looks like it may not be handling errors when entity ids do not exist.

It’s unrelated to entity IDs. As mentioned earlier, the issue arises from Node-RED sending a command that Home Assistant doesn’t have a handler for. The "unknown command" log you shared confirms this.

Here’s the relevant code in Home Assistant that returns the error message:
https://github.com/home-assistant/core/blob/249d93574ad42e5acc29b04753f607fe86ab3851/homeassistant/components/websocket_api/connection.py#L220-L227

Identifying the specific command being sent would save time and avoid the need to search through the entire codebase.

@marc-gist
Copy link
Author

@zachowj

2024-12-31 14:19:12.306 INFO (MainThread) [homeassistant.components.websocket_api.http.connection] [140039597697600] Received unknown command: config/floor_registry/list
2024-12-31 14:19:12.307 INFO (MainThread) [homeassistant.components.websocket_api.http.connection] [140039597697600] Received unknown command: config/label_registry/list

On HA
Core 2024.1.6
Frontend 20240104.0

@zachowj
Copy link
Owner

zachowj commented Dec 31, 2024

That makes sense. The label and floor registries were introduced in Home Assistant 2024.3.0. The minimum Home Assistant version requirement should have been updated when version 0.66.0 was released.

Thanks for helping pinpoint the exact cause of this issue!

@marc-gist
Copy link
Author

marc-gist commented Jan 1, 2025

That makes sense. The label and floor registries were introduced in Home Assistant 2024.3.0. The minimum Home Assistant version requirement should have been updated when version 0.66.0 was released.

Thanks for helping pinpoint the exact cause of this issue!

Thanks for the awesome integration and putting up with me, and helping me learn how to better debug. hopefully should I find another one I can provide better details from the start.

Could the code not catch these errors to maintain backward compatibility? I don't like updating HA very often on the one system as its a customer facing production "system" that runs.

take care!

@zachowj
Copy link
Owner

zachowj commented Jan 2, 2025

Could the code not catch these errors to maintain backward compatibility? I don't like updating HA very often on the one system as its a customer facing production "system" that runs.

Maintaining backward compatibility is always a priority, but in this case, the floor and label registries are now core requirements for several nodes. Adding workarounds or version gates to handle older Home Assistant versions would significantly increase maintenance complexity.

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

Successfully merging a pull request may close this issue.

3 participants