From 3a17a762334d9a45106321ef5dfdc43ffb848ed1 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 16 May 2023 21:34:34 +0100 Subject: [PATCH] Exit debug (#2554) * show single error by default * changelog * show numbers of errors * changelog --- CHANGELOG.md | 1 + src/textual/app.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 145e578a2..cd3e91dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - App `title` and `sub_title` attributes can be set to any type https://github.com/Textualize/textual/issues/2521 +- Only a single error will be written by default, unless in dev mode ("debug" in App.features) https://github.com/Textualize/textual/issues/2480 - Using `Widget.move_child` where the target and the child being moved are the same is now a no-op https://github.com/Textualize/textual/issues/1743 - Calling `dismiss` on a screen that is not at the top of the stack now raises an exception https://github.com/Textualize/textual/issues/2575 - `MessagePump.call_after_refresh` and `MessagePump.call_later` will not return `False` if the callback could not be scheduled. https://github.com/Textualize/textual/pull/2584 diff --git a/src/textual/app.py b/src/textual/app.py index 841d854e2..c8863d764 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -1630,8 +1630,22 @@ class App(Generic[ReturnType], DOMNode): def _print_error_renderables(self) -> None: """Print and clear exit renderables.""" - for renderable in self._exit_renderables: - self.error_console.print(renderable) + error_count = len(self._exit_renderables) + if "debug" in self.features: + for renderable in self._exit_renderables: + self.error_console.print(renderable) + if error_count > 1: + self.error_console.print( + f"\n[b]NOTE:[/b] {error_count} errors show above.", markup=True + ) + elif self._exit_renderables: + self.error_console.print(self._exit_renderables[0]) + if error_count > 1: + self.error_console.print( + f"\n[b]NOTE:[/b] 1 of {error_count} errors show. Run with [b]--dev[/] to see all errors.", + markup=True, + ) + self._exit_renderables.clear() async def _process_messages(