From 0afcb87bcd17a0b40b23b35e82cac65ce81a108e Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 30 Jan 2025 11:40:10 -0600 Subject: [PATCH] Make error messages a bit more informative in terms of who is causing the error --- shiny/reactive/_reactives.py | 2 +- shiny/ui/_chat.py | 3 ++- shiny/ui/_markdown_stream.py | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/shiny/reactive/_reactives.py b/shiny/reactive/_reactives.py index c83fd49a9..c509d0809 100644 --- a/shiny/reactive/_reactives.py +++ b/shiny/reactive/_reactives.py @@ -596,7 +596,7 @@ async def _run(self) -> None: from .._app import SANITIZE_ERROR_MSG from ..ui import notification_show - msg = "Error in Effect: " + str(e) + msg = str(e) if e.sanitize: msg = SANITIZE_ERROR_MSG notification_show(msg, type="error", duration=5000) diff --git a/shiny/ui/_chat.py b/shiny/ui/_chat.py index 61476cd48..9b3488152 100644 --- a/shiny/ui/_chat.py +++ b/shiny/ui/_chat.py @@ -377,7 +377,8 @@ async def _raise_exception( else: await self._remove_loading_message() sanitize = self.on_error == "sanitize" - raise NotifyException(str(e), sanitize=sanitize) from e + msg = f"Error in Chat('{self.id}'): {str(e)}" + raise NotifyException(msg, sanitize=sanitize) from e @overload def messages( diff --git a/shiny/ui/_markdown_stream.py b/shiny/ui/_markdown_stream.py index 98bffc4de..d017f84ab 100644 --- a/shiny/ui/_markdown_stream.py +++ b/shiny/ui/_markdown_stream.py @@ -179,7 +179,8 @@ async def _raise_exception(self, e: BaseException): raise e else: sanitize = self.on_error == "sanitize" - raise NotifyException(str(e), sanitize=sanitize) from e + msg = f"Error in MarkdownStream('{self.id}'): {str(e)}" + raise NotifyException(msg, sanitize=sanitize) from e def _send_custom_message(self, msg: Union[ContentMessage, isStreamingMessage]): if self._session.is_stub_session():