mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix dispatcher logging (#33299)
This commit is contained in:
parent
6cafc45d2b
commit
73c52e668e
@ -47,7 +47,10 @@ def async_dispatcher_connect(
|
|||||||
wrapped_target = catch_log_exception(
|
wrapped_target = catch_log_exception(
|
||||||
target,
|
target,
|
||||||
lambda *args: "Exception in {} when dispatching '{}': {}".format(
|
lambda *args: "Exception in {} when dispatching '{}': {}".format(
|
||||||
target.__name__, signal, args
|
# Functions wrapped in partial do not have a __name__
|
||||||
|
getattr(target, "__name__", None) or str(target),
|
||||||
|
signal,
|
||||||
|
args,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Test dispatcher helpers."""
|
"""Test dispatcher helpers."""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
@ -147,9 +148,13 @@ async def test_callback_exception_gets_logged(hass, caplog):
|
|||||||
"""Record calls."""
|
"""Record calls."""
|
||||||
raise Exception("This is a bad message callback")
|
raise Exception("This is a bad message callback")
|
||||||
|
|
||||||
async_dispatcher_connect(hass, "test", bad_handler)
|
# wrap in partial to test message logging.
|
||||||
|
async_dispatcher_connect(hass, "test", partial(bad_handler))
|
||||||
dispatcher_send(hass, "test", "bad")
|
dispatcher_send(hass, "test", "bad")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Exception in bad_handler when dispatching 'test': ('bad',)" in caplog.text
|
assert (
|
||||||
|
f"Exception in functools.partial({bad_handler}) when dispatching 'test': ('bad',)"
|
||||||
|
in caplog.text
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user