Ensure pretty traceback for error in Widget compose method (#1505)

* Ensure pretty traceback for error in Widget compose method

* Fail fast and pretty tracebacks for Widget compose errors
This commit is contained in:
darrenburns
2023-01-06 16:28:34 +00:00
committed by Rodrigo Girão Serrão
parent 1e8162e8d0
commit c22cc30e71
2 changed files with 6 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed ### Changed
- `MouseScrollUp` and `MouseScrollDown` now inherit from `MouseEvent` and have attached modifier keys. https://github.com/Textualize/textual/pull/1458 - `MouseScrollUp` and `MouseScrollDown` now inherit from `MouseEvent` and have attached modifier keys. https://github.com/Textualize/textual/pull/1458
- Fail-fast and print pretty tracebacks for Widget compose errors https://github.com/Textualize/textual/pull/1505
### Fixed ### Fixed

View File

@@ -33,6 +33,7 @@ from rich.measure import Measurement
from rich.segment import Segment from rich.segment import Segment
from rich.style import Style from rich.style import Style
from rich.text import Text from rich.text import Text
from rich.traceback import Traceback
from . import errors, events, messages from . import errors, events, messages
from ._animator import DEFAULT_EASING, Animatable, BoundAnimator, EasingFunction from ._animator import DEFAULT_EASING, Animatable, BoundAnimator, EasingFunction
@@ -2333,7 +2334,10 @@ class Widget(DOMNode):
raise TypeError( raise TypeError(
f"{self!r} compose() returned an invalid response; {error}" f"{self!r} compose() returned an invalid response; {error}"
) from None ) from None
await self.mount(*widgets) except Exception:
self.app.panic(Traceback())
else:
await self.mount(*widgets)
def _on_mount(self, event: events.Mount) -> None: def _on_mount(self, event: events.Mount) -> None:
if self.styles.overflow_y == "scroll": if self.styles.overflow_y == "scroll":