Skip to content

Commit

Permalink
Merge pull request #1887 from Textualize/exceptions-from-mount
Browse files Browse the repository at this point in the history
catch exceptions from post mount
  • Loading branch information
willmcgugan authored Feb 26, 2023
2 parents 0d082ef + 8ba7893 commit f16f9c2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed

- Fix exceptions in watch methods being hidden on startup https://github.com/Textualize/textual/issues/1886

## [0.12.1] - 2023-02-25

Expand Down
1 change: 1 addition & 0 deletions src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def get_component_styles(self, name: str) -> RenderStyles:

def _post_mount(self):
"""Called after the object has been mounted."""
_rich_traceback_omit = True
Reactive._initialize_object(self)

def notify_style_update(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/textual/message_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,12 @@ async def _pre_process(self) -> None:
try:
await self._dispatch_message(events.Compose(sender=self))
await self._dispatch_message(events.Mount(sender=self))
self._post_mount()
except Exception as error:
self.app._handle_exception(error)
finally:
# This is critical, mount may be waiting
self._mounted_event.set()
self._post_mount()

def _post_mount(self):
"""Called after the object has been mounted."""
Expand Down
4 changes: 3 additions & 1 deletion src/textual/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ def _initialize_reactive(self, obj: Reactable, name: str) -> None:
obj: An object with reactive attributes.
name: Name of attribute.
"""
_rich_traceback_omit = True
internal_name = f"_reactive_{name}"
if hasattr(obj, internal_name):
# Attribute already has a value
return

compute_method = getattr(obj, f"compute_{name}", None)
if compute_method is not None and self._init:
default = getattr(obj, f"compute_{name}")()
Expand All @@ -114,7 +116,7 @@ def _initialize_object(cls, obj: Reactable) -> None:
Args:
obj: An object with Reactive descriptors
"""

_rich_traceback_omit = True
for name, reactive in obj._reactives.items():
reactive._initialize_reactive(obj, name)

Expand Down

0 comments on commit f16f9c2

Please sign in to comment.