Merge pull request #1887 from Textualize/exceptions-from-mount

catch exceptions from post mount
This commit is contained in:
Will McGugan
2023-02-26 22:28:56 +00:00
committed by GitHub
4 changed files with 10 additions and 2 deletions

View File

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

View File

@@ -221,6 +221,7 @@ class DOMNode(MessagePump):
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:

View File

@@ -429,12 +429,12 @@ class MessagePump(metaclass=MessagePumpMeta):
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."""

View File

@@ -89,10 +89,12 @@ class Reactive(Generic[ReactiveType]):
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}")()
@@ -114,7 +116,7 @@ class Reactive(Generic[ReactiveType]):
Args:
obj: An object with Reactive descriptors
"""
_rich_traceback_omit = True
for name, reactive in obj._reactives.items():
reactive._initialize_reactive(obj, name)