-
-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ServiceValidationError and translation support (#1961)
* Add ServiceValidationError and translation support * Improvements, add blog post * Add error handling response * Follow up comment * Update blog/2023-10-29-service-exceptions-and-translations.md Co-authored-by: Martin Hjelmare <[email protected]> * Update blog/2023-10-29-service-exceptions-and-translations.md Co-authored-by: Martin Hjelmare <[email protected]> * Follow up raising vs handling errors * Fix links * Update docs/core/platform/raising_exceptions.md Co-authored-by: Martin Hjelmare <[email protected]> * Update blog/2023-10-29-service-exceptions-and-translations.md Co-authored-by: Martin Hjelmare <[email protected]> * Update docs/api/websocket.md Co-authored-by: Martin Hjelmare <[email protected]> * Update docs/internationalization/core.md Co-authored-by: Martin Hjelmare <[email protected]> * Update docs/internationalization/core.md Co-authored-by: Martin Hjelmare <[email protected]> * Update docs/core/platform/raising_exceptions.md Co-authored-by: Martin Hjelmare <[email protected]> * Update docs/integration_quality_scale_index.md Co-authored-by: Martin Hjelmare <[email protected]> * Update docs/internationalization/core.md Co-authored-by: Martin Hjelmare <[email protected]> * Update blog/2023-10-29-service-exceptions-and-translations.md Co-authored-by: Martin Hjelmare <[email protected]> * Rename file to adjust date --------- Co-authored-by: Martin Hjelmare <[email protected]>
- Loading branch information
1 parent
32fbbb4
commit f85fa4c
Showing
6 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
author: Jan Bouwhuis | ||
authorURL: https://github.com/jbouwh | ||
authorImageURL: https://avatars.githubusercontent.com/u/7188918?s=96&v=4 | ||
title: Exception handling during 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. | ||
|
||
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). | ||
|
||
## Translation support for Exceptions | ||
|
||
The `HomeAssistantError` exception and its subclasses, including `ServiceValidationError`, now accept a translation key to allow localization. [Read more](/docs/internationalization/core/#exceptions). The translation key will be used in cases where the frontend receives information about the exception. | ||
|
||
### Background | ||
|
||
- Background [discussion](https://github.com/home-assistant/architecture/discussions/992). | ||
- Implementation [Core PR #102592](https://github.com/home-assistant/core/pull/102592). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
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. | ||
|
||
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. | ||
|
||
## Localizing Exceptions | ||
|
||
Home Assistant [supports localization](/docs/internationalization/core/#exceptions) for `HomeAssistantError` and its subclasses like `ServiceValidationError`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters