mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Log stack trace if exception without message (#67587)
This commit is contained in:
parent
57ffc65af2
commit
fbc39d1206
@ -121,6 +121,9 @@ class ActiveConnection:
|
||||
"""Handle an exception while processing a handler."""
|
||||
log_handler = self.logger.error
|
||||
|
||||
code = const.ERR_UNKNOWN_ERROR
|
||||
err_message = None
|
||||
|
||||
if isinstance(err, Unauthorized):
|
||||
code = const.ERR_UNAUTHORIZED
|
||||
err_message = "Unauthorized"
|
||||
@ -131,13 +134,15 @@ class ActiveConnection:
|
||||
code = const.ERR_TIMEOUT
|
||||
err_message = "Timeout"
|
||||
elif isinstance(err, HomeAssistantError):
|
||||
code = const.ERR_UNKNOWN_ERROR
|
||||
err_message = str(err)
|
||||
else:
|
||||
code = const.ERR_UNKNOWN_ERROR
|
||||
|
||||
# This if-check matches all other errors but also matches errors which
|
||||
# result in an empty message. In that case we will also log the stack
|
||||
# trace so it can be fixed.
|
||||
if not err_message:
|
||||
err_message = "Unknown error"
|
||||
log_handler = self.logger.exception
|
||||
|
||||
log_handler("Error handling message: %s", err_message)
|
||||
log_handler("Error handling message: %s (%s)", err_message, code)
|
||||
|
||||
self.send_message(messages.error_message(msg["id"], code, err_message))
|
||||
|
@ -54,6 +54,11 @@ async def test_exception_handling():
|
||||
"Failed to do X",
|
||||
),
|
||||
(ValueError("Really bad"), websocket_api.ERR_UNKNOWN_ERROR, "Unknown error"),
|
||||
(
|
||||
exceptions.HomeAssistantError(),
|
||||
websocket_api.ERR_UNKNOWN_ERROR,
|
||||
"Unknown error",
|
||||
),
|
||||
):
|
||||
send_messages.clear()
|
||||
conn.async_handle_exception({"id": 5}, exc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user