From 414c49a00720d23c7f4be544f0bea184a060dc8f Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Mon, 29 Jan 2024 16:43:36 -0500 Subject: [PATCH] fix(repr): force exception message to console in IPython in interactive mode --- ibis/expr/types/relations.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ibis/expr/types/relations.py b/ibis/expr/types/relations.py index 0de72054d9c4..96cfe2e68535 100644 --- a/ibis/expr/types/relations.py +++ b/ibis/expr/types/relations.py @@ -365,7 +365,25 @@ def __interactive_rich_console__(self, console, options): else: width = options.max_width - table = to_rich_table(self, width) + try: + table = to_rich_table(self, width) + except Exception as e: + # In IPython exceptions inside of _repr_mimebundle_ are swallowed to + # allow calling several display functions and choosing to display + # the "best" result based on some priority. + # This behavior, though, means that exceptions that bubble up inside of the interactive repr + # are silently caught. + # + # We can't stop the exception from being swallowed, but we can force + # the display of that exception as we do here. + # + # A _very_ annoying caveat is that this exception is _not_ being + # ` raise`d, it is only being printed to the console. This means + # that you cannot "catch" it. + # + # This restriction is only present in IPython, not in other REPLs. + console.print_exception() + raise e return console.render(table, options=options) def __getitem__(self, what):