mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-07 17:36:29 +00:00
Adjust language in blog post about exception handling during service calls (#2004)
* Adjust language in blog post about exception handling during service calls * Update 2023-11-30-service-exceptions-and-translations.md * Language adjustments according to review comments * Fix typo --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
7b109160ce
commit
cc7363b628
@ -7,11 +7,15 @@ title: Exception handling during service calls and translation support
|
||||
|
||||
## Exception handling during service calls
|
||||
|
||||
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.
|
||||
Service calls which raise exceptions have until now logged stack traces. Service calls that fail due to incorrect usage, for example invalid input, don't need a stack trace and would benefit from a helpful error message in the user's 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.
|
||||
To be able to suppress the stack trace in these cases, the new exception type `ServiceValidationError`, which is derived from `HomeAssistantError`, has been introduced. `ServiceValidationError` should now be raised instead of `ValueError` when the service fails because it's used incorrectly.
|
||||
|
||||
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).
|
||||
If the service is used correctly but still fails, `HomeAssistantError`, or a subclass of `HomeAssistantError` other than `ServiceValidationError`, should still be raised.
|
||||
|
||||
When a service raises `ServiceValidationError`, the error message will show in the UI, and in the logs, but the stack trace is logged at debug level. For other exceptions that are raised from a service call (including `HomeAssistantError`) nothing changes and a full stack trace is still printed at exception severity.
|
||||
|
||||
Integrations should be updated and raise `ServiceValidationError` instead of `ValueError` when the the service fails due to incorrect usage, and `HomeAssistantError` when it fails for other expected errors, for example a network error. [Read more](/docs/core/platform/raising_exceptions).
|
||||
|
||||
## Translation support for Exceptions
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user