diff --git a/NEWS b/NEWS index 468d884..3e23f66 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,7 @@ Changes from 0.13.0 * Fixed a crash when `macroexpand`ing a macro with a named import * Fixed a crash when `with` suppresses an exception. `with` now returns `None` in this case. + * Fixed a crash when --repl-output-fn raises an exception * `assoc` now evaluates its arguments only once each * `break` and `continue` now raise an error when given arguments instead of silently ignoring them diff --git a/hy/cmdline.py b/hy/cmdline.py index a9d966c..fb58539 100644 --- a/hy/cmdline.py +++ b/hy/cmdline.py @@ -115,7 +115,12 @@ class HyREPL(code.InteractiveConsole): # the user as `_`. self.locals['_'] = value # Print the value. - print(self.output_fn(value)) + try: + output = self.output_fn(value) + except Exception: + self.showtraceback() + return False + print(output) return False diff --git a/tests/test_bin.py b/tests/test_bin.py index 6df4d43..670b77a 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -132,6 +132,16 @@ def test_bin_hy_stdin_except_do(): assert "zzz" in output +def test_bin_hy_stdin_bad_repr(): + # https://github.com/hylang/hy/issues/1389 + output, err = run_cmd("hy", """ + (defclass BadRepr [] (defn __repr__ [self] (/ 0))) + (BadRepr) + (+ "A" "Z")""") + assert "ZeroDivisionError" in err + assert "AZ" in output + + def test_bin_hy_stdin_hy_repr(): output, _ = run_cmd("hy", '(+ [1] [2])') assert "[1, 2]" in output.replace('L', '')