If the __repr__ of a local object fails, it gets reported as "<broken repr>":
| ifPY2: |
| |
| defsafe_repr(value): |
| # type: (Any) -> str |
| try: |
| rv=repr(value).decode("utf-8", "replace") |
| |
| # At this point `rv` contains a bunch of literal escape codes, like |
| # this (exaggerated example): |
| # |
| # u"\\x2f" |
| # |
| # But we want to show this string as: |
| # |
| # u"/" |
| try: |
| # unicode-escape does this job, but can only decode latin1. So we |
| # attempt to encode in latin1. |
| returnrv.encode("latin1").decode("unicode-escape") |
| exceptException: |
| # Since usually strings aren't latin1 this can break. In those |
| # cases we just give up. |
| returnrv |
| exceptException: |
| # If e.g. the call to `repr` already fails |
| returnu"<broken repr>" |
| |
| |
| else: |
| |
| defsafe_repr(value): |
| # type: (Any) -> str |
| try: |
| returnrepr(value) |
| exceptException: |
| return"<broken repr>" |
It would be more helpful if it would include more information there, e.g. at least the class name of the exception.
It could also be something more sophisticated like:
def_try_repr_or_str(obj):
try:
returnrepr(obj)
except (KeyboardInterrupt, SystemExit):
raiseexceptBaseException:
return'{}("{}")'.format(type(obj).__name__, obj)
def_format_repr_exception(exc: BaseException, obj: Any) ->str:
try:
exc_info=_try_repr_or_str(exc)
except (KeyboardInterrupt, SystemExit):
raiseexceptBaseExceptionasexc:
exc_info="unpresentable exception ({})".format(_try_repr_or_str(exc))
return"<[{} raised in repr()] {} object at 0x{:x}>".format(
exc_info, type(obj).__name__, id(obj)
)(via https://github.com/blueyed/pytest/blob/8eb380425395332ffdf2cd42b8d7cf8ffab2ea2e/src/_pytest/_io/saferepr.py#L6-L24)
This would help with investigating why a repr is broken actually, e.g. with celery/py-amqp#361.
(slightly related: there was some related (still open) PR for raven-python about this already: getsentry/raven-python#1294)
If the
__repr__of a local object fails, it gets reported as "<broken repr>":sentry-python/sentry_sdk/utils.py
Lines 416 to 451 in d7cf16c
It would be more helpful if it would include more information there, e.g. at least the class name of the exception.
It could also be something more sophisticated like:
(via https://github.com/blueyed/pytest/blob/8eb380425395332ffdf2cd42b8d7cf8ffab2ea2e/src/_pytest/_io/saferepr.py#L6-L24)
This would help with investigating why a
repris broken actually, e.g. with celery/py-amqp#361.(slightly related: there was some related (still open) PR for raven-python about this already: getsentry/raven-python#1294)