From 3616bb5bfd8537676e57893c678432d0b08aacf8 Mon Sep 17 00:00:00 2001 From: Aman Goel Date: Thu, 10 Mar 2022 02:06:25 +0530 Subject: [PATCH 1/5] feat: add error handling to prevent crash --- src/uproot_browser/plot_view.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/uproot_browser/plot_view.py b/src/uproot_browser/plot_view.py index db71939..0782f9f 100644 --- a/src/uproot_browser/plot_view.py +++ b/src/uproot_browser/plot_view.py @@ -38,8 +38,22 @@ def __rich_console__( ) -> rich.console.RenderResult: width = options.max_width or console.width height = options.height or console.height - canvas = make_plot(self.item, width, height) - rich_canvas = rich.console.Group(*self.decoder.decode(canvas)) + try: + canvas = make_plot(self.item, width, height) + rich_canvas = rich.console.Group(*self.decoder.decode(canvas)) + except Exception: + rich_canvas = rich.console.Group( + rich.traceback.Traceback( + extra_lines=1, + max_frames=4, # Can't be less than 4 frames + ) + ) + + if options.height is not None: + options.height -= 4 + yield from rich_canvas.__rich_console__(console, options) + return + yield rich_canvas From 33ec1caf3f0427477b6da8f418c4a954e0c7fdbf Mon Sep 17 00:00:00 2001 From: Aman Goel Date: Thu, 10 Mar 2022 02:33:33 +0530 Subject: [PATCH 2/5] fix: disable broad-except in PyLint --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index e6a43db..30b39f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,3 +112,4 @@ messages_control.disable = [ "missing-function-docstring", "missing-module-docstring", ] +disable = "broad-except" From fe2f592d89e39965e32501c19b47b3f9f29d6264 Mon Sep 17 00:00:00 2001 From: Aman Goel Date: Thu, 10 Mar 2022 02:46:14 +0530 Subject: [PATCH 3/5] fix: update syntax in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 30b39f8..eb0aed5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,5 +111,5 @@ messages_control.disable = [ "missing-class-docstring", "missing-function-docstring", "missing-module-docstring", + "broad-except" ] -disable = "broad-except" From 27e818cd7f544dd9c4ada6afcfc01253bcf5dba6 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 9 Mar 2022 17:01:05 -0500 Subject: [PATCH 4/5] refactor: remove group --- src/uproot_browser/plot_view.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/uproot_browser/plot_view.py b/src/uproot_browser/plot_view.py index 0782f9f..d5b25c9 100644 --- a/src/uproot_browser/plot_view.py +++ b/src/uproot_browser/plot_view.py @@ -40,7 +40,7 @@ def __rich_console__( height = options.height or console.height try: canvas = make_plot(self.item, width, height) - rich_canvas = rich.console.Group(*self.decoder.decode(canvas)) + yield rich.console.Group(*self.decoder.decode(canvas)) except Exception: rich_canvas = rich.console.Group( rich.traceback.Traceback( @@ -52,9 +52,6 @@ def __rich_console__( if options.height is not None: options.height -= 4 yield from rich_canvas.__rich_console__(console, options) - return - - yield rich_canvas class PlotWidget(textual.widget.Widget): # type: ignore[misc] From 65a5d8e2bc4d6a3bf54a3bc1f1f960ba5ee9bd96 Mon Sep 17 00:00:00 2001 From: Aman Goel Date: Thu, 10 Mar 2022 04:46:03 +0530 Subject: [PATCH 5/5] refactor: remove group wrapper --- src/uproot_browser/plot_view.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/uproot_browser/plot_view.py b/src/uproot_browser/plot_view.py index d5b25c9..8471e46 100644 --- a/src/uproot_browser/plot_view.py +++ b/src/uproot_browser/plot_view.py @@ -42,11 +42,9 @@ def __rich_console__( canvas = make_plot(self.item, width, height) yield rich.console.Group(*self.decoder.decode(canvas)) except Exception: - rich_canvas = rich.console.Group( - rich.traceback.Traceback( - extra_lines=1, - max_frames=4, # Can't be less than 4 frames - ) + rich_canvas = rich.traceback.Traceback( + extra_lines=1, + max_frames=4, # Can't be less than 4 frames ) if options.height is not None: