-
-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ServiceValidationError and translation support #1961
Merged
jbouwh
merged 18 commits into
home-assistant:master
from
jbouwh:service-validation-error-and-translations
Nov 17, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6973e85
Add ServiceValidationError and translation support
jbouwh b3ead14
Improvements, add blog post
jbouwh 5d8d2e0
Add error handling response
jbouwh c384d57
Follow up comment
jbouwh 7cfa6f2
Update blog/2023-10-29-service-exceptions-and-translations.md
jbouwh 252ed8a
Update blog/2023-10-29-service-exceptions-and-translations.md
jbouwh 17b492b
Follow up raising vs handling errors
jbouwh 6472af5
Fix links
jbouwh 53bc2ac
Update docs/core/platform/raising_exceptions.md
jbouwh 375183a
Update blog/2023-10-29-service-exceptions-and-translations.md
jbouwh 27aabe2
Update docs/api/websocket.md
jbouwh 02a9907
Update docs/internationalization/core.md
jbouwh 7bf0096
Update docs/internationalization/core.md
jbouwh 966f2ea
Update docs/core/platform/raising_exceptions.md
jbouwh 5fa0f77
Update docs/integration_quality_scale_index.md
jbouwh ea3c813
Update docs/internationalization/core.md
jbouwh 6ce89f6
Update blog/2023-10-29-service-exceptions-and-translations.md
jbouwh 39e0ac8
Rename file to adjust date
jbouwh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbouwh where does this variable come from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. It should be a static string with a message to be logged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1991