diff --git a/CHANGELOG.md b/CHANGELOG.md index 52db0457b..bc33feab4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Allow exceptions that are raised while a Live is rendered to be displayed and/or processed https://github.com/Textualize/rich/pull/2305 + ## [12.4.4] - 2022-05-24 ### Changed diff --git a/rich/live.py b/rich/live.py index 6db5b605f..e635fe5c9 100644 --- a/rich/live.py +++ b/rich/live.py @@ -118,7 +118,15 @@ def start(self, refresh: bool = False) -> None: self._enable_redirect_io() self.console.push_render_hook(self) if refresh: - self.refresh() + try: + self.refresh() + except Exception: + # If refresh fails, we want to stop the redirection of sys.stderr, + # so the error stacktrace is properly displayed in the terminal. + # (or, if the code that calls Rich captures the exception and wants to display something, + # let this be displayed in the terminal). + self.stop() + raise if self.auto_refresh: self._refresh_thread = _RefreshThread(self, self.refresh_per_second) self._refresh_thread.start()