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

Exceptions from watch methods are swallowed on startup #1886

Closed
willmcgugan opened this issue Feb 26, 2023 · 1 comment · Fixed by #1887
Closed

Exceptions from watch methods are swallowed on startup #1886

willmcgugan opened this issue Feb 26, 2023 · 1 comment · Fixed by #1887

Comments

@willmcgugan
Copy link
Collaborator

willmcgugan commented Feb 26, 2023

Copied from Discord...

from textual.reactive import reactive
from textual.widgets import Footer, Header, Static


class UnhandledExceptionTest(App):
    BINDINGS = [("q", "quit", "Quit")]

    def compose(self) -> ComposeResult:
        yield Header()
        yield MyStatic()
        yield Footer()

    def on_mount(self):
        self.query_one(MyStatic).contents = "Hello, World!"


class MyStatic(Static):
    contents = reactive(None, always_update=True)

    def watch_contents(self, new):
        self.update(new.upper())


if __name__ == "__main__":
    UnhandledExceptionTest().run()

The upper in watch_contents throws an exception because the initial value of the reactive attribute is None. Yes, this would not happen in real life as the type checker warns about it, but it does work to show how the exception is gobbled up.
I just can't figure out why my bigger app will terminate in 0.11 but not 0.12, but that demo code above does gobble the exception and does not terminate in both 0.11 and 0.12.
(at least on my two different machines, a work computer and home computer)

@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant