Skip to content

Exception messages can lack detail when using str(e) #22

@theferrit32

Description

@theferrit32

For input variants which don't have a source field because there is no representation, the output in the errors field is just "source".

This is because

>>> d = {"A": 1}
>>> try: d["source"]
... except Exception as e: print(str(e))
...
'source'

even though

>>> d["source"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'source'

Using repr(e) instead using the default str(e) conversion would be a quick way to add a bit more context without needing to add if checks on all key accesses.

>>> try: d["source"]
... except Exception as e: print(repr(e))
...
KeyError('source')

return {"errors": str(e)}

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