Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure pretty traceback for error in Widget compose method #1505

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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