Merge pull request #1403 from Kodiologist/exceptional-output-fn
Catch exceptions raised by HyREPL.output_fn
This commit is contained in:
commit
4b2cc5f297
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 `macroexpand`ing a macro with a named import
|
||||||
* Fixed a crash when `with` suppresses an exception. `with` now returns
|
* Fixed a crash when `with` suppresses an exception. `with` now returns
|
||||||
`None` in this case.
|
`None` in this case.
|
||||||
|
* Fixed a crash when --repl-output-fn raises an exception
|
||||||
* `assoc` now evaluates its arguments only once each
|
* `assoc` now evaluates its arguments only once each
|
||||||
* `break` and `continue` now raise an error when given arguments
|
* `break` and `continue` now raise an error when given arguments
|
||||||
instead of silently ignoring them
|
instead of silently ignoring them
|
||||||
|
@ -115,7 +115,12 @@ class HyREPL(code.InteractiveConsole):
|
|||||||
# the user as `_`.
|
# the user as `_`.
|
||||||
self.locals['_'] = value
|
self.locals['_'] = value
|
||||||
# Print the 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
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,6 +132,16 @@ def test_bin_hy_stdin_except_do():
|
|||||||
assert "zzz" in output
|
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():
|
def test_bin_hy_stdin_hy_repr():
|
||||||
output, _ = run_cmd("hy", '(+ [1] [2])')
|
output, _ = run_cmd("hy", '(+ [1] [2])')
|
||||||
assert "[1, 2]" in output.replace('L', '')
|
assert "[1, 2]" in output.replace('L', '')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user