Skip to content

When errors occur in display formatting, the traceback is displayed as error but execute_reply is marked as success #1520

@krassowski

Description

@krassowski

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:

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.

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/0

See status "error"

Image

Then execute:

class Test:
    def __repr__(self):
        1 / 0

Test()

See status "ok":

Image

Context

Noticed in:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions