mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-15 05:16:28 +00:00
Update blog and docs on exception handling (#1988)
This commit is contained in:
parent
2456fcc659
commit
f8dafa2c3c
@ -9,7 +9,9 @@ title: Exception handling during service calls and translation support
|
||||
|
||||
Currently service calls that raise exceptions will log full stack traces. Service calls that fail due to invalid user input don't need a stack trace but would benefit from a helpful error message in the users own language.
|
||||
|
||||
To be able to suppress the stack trace in these cases, we introduce `ServiceValidationError` as a new exception type. The `ServiceValidationError` exception can be raised instead of `HomeAssistantError` during the execution of a service call. The error message will show in the UI, and in the logs. The stack trace is printed at debug level, to support development. For other exceptions that are raised from a service call (including `HomeAssistantError`) nothing changes and a full stack trace is printed. [Read more](/docs/core/platform/raising_exceptions).
|
||||
To be able to suppress the stack trace in these cases, we introduce `ServiceValidationError` as a new exception type. The `ServiceValidationError` exception can be raised instead of `HomeAssistantError` during the execution of a service call. The error message will show in the UI, and in the logs. The stack trace is printed at debug level, to support development. For other exceptions that are raised from a service call (including `HomeAssistantError`) nothing changes and a full stack trace is printed.
|
||||
|
||||
Integrations should be updated and raise `ServiceValidationError` instead of `ValueError` when the user did something wrong, and `HomeAssistantError` when it's not the user's fault. [Read more](/docs/core/platform/raising_exceptions).
|
||||
|
||||
## Translation support for Exceptions
|
||||
|
@ -2,9 +2,13 @@
|
||||
title: "Raising Exceptions"
|
||||
---
|
||||
|
||||
Operations like service calls and entity methods (e.g. *Set HVAC Mode*) should raise exceptions properly. Raise `ServiceValidationError` on an invalid user input and raise `HomeAssistantError` for other failures such as a problem communicating with a device. Note that the exception stack trace will be logged.
|
||||
## Raising Exceptions in service handlers
|
||||
|
||||
Raise `ServiceValidationError` for validation errors that occur during service calls where printing a full stack trace to the logs is not warranted. This exception class will only log exception stack traces at debug level.
|
||||
Operations like service calls and entity methods (e.g. *Set HVAC Mode*) should raise exceptions properly.
|
||||
|
||||
Integrations should raise `ServiceValidationError` (instead of `ValueError`) in case when the user did something wrong. In this case a stack trace will only be printed at debug level.
|
||||
|
||||
For other failures such as a problem communicating with a device, `HomeAssistantError` should be raised. Note that the exception stack trace will be printed to the log in this case.
|
||||
|
||||
## Localizing Exceptions
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user