From cc7363b628867734027ae4f001bc36792e5f500c Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 22 Dec 2023 02:01:58 +0100 Subject: [PATCH] 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 --- blog/2023-11-30-service-exceptions-and-translations.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/blog/2023-11-30-service-exceptions-and-translations.md b/blog/2023-11-30-service-exceptions-and-translations.md index 3ee8d0c8..bb0147b0 100644 --- a/blog/2023-11-30-service-exceptions-and-translations.md +++ b/blog/2023-11-30-service-exceptions-and-translations.md @@ -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