Catch exceptions raised by HyREPL.output_fn
This commit is contained in:
parent
3db13ec71f
commit
e3e7fa8ce6
1
NEWS
1
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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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', '')
|
||||
|
Loading…
Reference in New Issue
Block a user