Skip to content

Commit

Permalink
Merge pull request #1403 from Kodiologist/exceptional-output-fn
Browse files Browse the repository at this point in the history
Catch exceptions raised by HyREPL.output_fn
  • Loading branch information
kirbyfan64 committed Aug 29, 2017
2 parents 3db13ec + e3e7fa8 commit 4b2cc5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion hy/cmdline.py
Expand Up @@ -115,7 +115,12 @@ def ast_callback(main_ast, expr_ast):
# 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


Expand Down
10 changes: 10 additions & 0 deletions tests/test_bin.py
Expand Up @@ -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', '')
Expand Down

0 comments on commit 4b2cc5f

Please sign in to comment.