Catch exceptions raised by HyREPL.output_fn

This commit is contained in:
Kodi Arfer 2017-08-29 14:54:26 -07:00
parent 3db13ec71f
commit e3e7fa8ce6
3 changed files with 17 additions and 1 deletions

1
NEWS
View File

@ -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

View File

@ -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

View File

@ -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', '')