From a489293c86702ade4582b4a4a0b8f3bc0977c739 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Fri, 12 May 2023 11:27:38 -0400 Subject: [PATCH] Make display code more robust (#15) Make display code more robust --- kork/display.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kork/display.py b/kork/display.py index 60381ce..74749f3 100644 --- a/kork/display.py +++ b/kork/display.py @@ -42,8 +42,6 @@ class HtmlResult(TypedDict): class _NoExpectedAnswer: """A sentinel class to indicate that there is no expected answer.""" - pass - NO_EXPECTED_ANSWER = _NoExpectedAnswer() @@ -61,7 +59,12 @@ def as_html_dict( code = code_result["code"].strip() if pretty_print: - code = AstPrinter().visit(parse(code), pretty_print=True) + try: + code = AstPrinter().visit(parse(code), pretty_print=True) + except Exception: + # This is display code. Broad exception handling OK for now + # we can make the code more robust later. + code = code else: code = code