Fix error stack trace for HomeAssistantError in websocket service call (#145699)
* Add test * Fix error stack trace for HomeAssistantError in websocket service callpull/145702/head
parent
2605fda185
commit
f295d72cd9
|
@ -300,7 +300,9 @@ async def handle_call_service(
|
|||
translation_placeholders=err.translation_placeholders,
|
||||
)
|
||||
except HomeAssistantError as err:
|
||||
connection.logger.exception("Unexpected exception")
|
||||
connection.logger.error(
|
||||
"Error during service call to %s.%s: %s", msg["domain"], msg["service"], err
|
||||
)
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
const.ERR_HOME_ASSISTANT_ERROR,
|
||||
|
|
|
@ -514,9 +514,12 @@ async def test_call_service_schema_validation_error(
|
|||
|
||||
@pytest.mark.parametrize("ignore_translations_for_mock_domains", ["test"])
|
||||
async def test_call_service_error(
|
||||
hass: HomeAssistant, websocket_client: MockHAClientWebSocket
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
websocket_client: MockHAClientWebSocket,
|
||||
) -> None:
|
||||
"""Test call service command with error."""
|
||||
caplog.set_level(logging.ERROR)
|
||||
|
||||
@callback
|
||||
def ha_error_call(_):
|
||||
|
@ -561,6 +564,7 @@ async def test_call_service_error(
|
|||
assert msg["error"]["translation_placeholders"] == {"option": "bla"}
|
||||
assert msg["error"]["translation_key"] == "custom_error"
|
||||
assert msg["error"]["translation_domain"] == "test"
|
||||
assert "Traceback" not in caplog.text
|
||||
|
||||
await websocket_client.send_json_auto_id(
|
||||
{
|
||||
|
@ -578,6 +582,7 @@ async def test_call_service_error(
|
|||
assert msg["error"]["translation_placeholders"] == {"option": "bla"}
|
||||
assert msg["error"]["translation_key"] == "custom_error"
|
||||
assert msg["error"]["translation_domain"] == "test"
|
||||
assert "Traceback" not in caplog.text
|
||||
|
||||
await websocket_client.send_json_auto_id(
|
||||
{
|
||||
|
@ -592,6 +597,7 @@ async def test_call_service_error(
|
|||
assert msg["success"] is False
|
||||
assert msg["error"]["code"] == "unknown_error"
|
||||
assert msg["error"]["message"] == "value_error"
|
||||
assert "Traceback" in caplog.text
|
||||
|
||||
|
||||
async def test_subscribe_unsubscribe_events(
|
||||
|
|
Loading…
Reference in New Issue