Skip to content

Commit

Permalink
Ensure pretty traceback for error in Widget compose method (#1505)
Browse files Browse the repository at this point in the history
* Ensure pretty traceback for error in Widget compose method

* Fail fast and pretty tracebacks for Widget compose errors
  • Loading branch information
darrenburns authored Jan 6, 2023
1 parent 82dcf62 commit a133bd8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- `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

Expand Down
6 changes: 5 additions & 1 deletion src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from rich.segment import Segment
from rich.style import Style
from rich.text import Text
from rich.traceback import Traceback

from . import errors, events, messages
from ._animator import DEFAULT_EASING, Animatable, BoundAnimator, EasingFunction
Expand Down Expand Up @@ -2333,7 +2334,10 @@ async def _on_compose(self) -> None:
raise TypeError(
f"{self!r} compose() returned an invalid response; {error}"
) 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:
if self.styles.overflow_y == "scroll":
Expand Down

0 comments on commit a133bd8

Please sign in to comment.