Repository navigation
Description
Description
When an error occurs during display formatting, the traceback is displayed as error but execute_reply is marked as success.
Based on discussion in:
- IPython magic UsageErrors do not set status:error on execute_reply #143
- Simplify detection of errors for execute_reply messages #152
I suspect that this might have been lost in ipykernel unintentionally in or following #152. Since that PR did not include tests and removed exc_content[u'status'] = u'error' from _showtraceback replacing it with unified error handling, I think that either it or a subsequent regression in unified error handling made the traceback no longer mark execution as failed.
ipykernel/ipykernel/zmqshell.py
Lines 666 to 690 in 2818b66
| def _showtraceback(self, etype, evalue, stb): | |
| # try to preserve ordering of tracebacks and print statements | |
| sys.stdout.flush() | |
| sys.stderr.flush() | |
| exc_content = { | |
| "traceback": stb, | |
| "ename": str(etype.__name__), | |
| "evalue": str(evalue), | |
| } | |
| dh = self.displayhook | |
| # Send exception info over pub socket for other clients than the caller | |
| # to pick up | |
| topic = None | |
| if dh.topic: # type:ignore[attr-defined] | |
| topic = dh.topic.replace(b"execute_result", b"error") # type:ignore[attr-defined] | |
| dh.session.send( # type:ignore[attr-defined] | |
| dh.pub_socket, # type:ignore[attr-defined] | |
| "error", | |
| json_clean(exc_content), | |
| dh.parent_header, # type:ignore[attr-defined] | |
| ident=topic, | |
| ) |
_showtraceback is relevant because in IPython formatters are decorated by @catch_format_error which displays any exception caught during the formatting routine using ip.showtraceback() delegated in subclasses - such as ipykernel's to _showtraceback().
Reproduce
Execute:
1/0See status "error"
Then execute:
class Test:
def __repr__(self):
1 / 0
Test()See status "ok":
Context
Noticed in:
Activity