From f81d2bfdc7f453082abee8cac6d30a3e880b3405 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 14 Jun 2023 19:44:01 +0100 Subject: [PATCH] fix: str of `KeyError` for <3.11 (#2519) Co-authored-by: Jim Pivarski --- src/awkward/_errors.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/awkward/_errors.py b/src/awkward/_errors.py index 738e0aa393..f6d8ccb982 100644 --- a/src/awkward/_errors.py +++ b/src/awkward/_errors.py @@ -1,6 +1,7 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE from __future__ import annotations +import builtins import sys import threading import warnings @@ -31,6 +32,11 @@ def __call__(self): return self.func(*self.args, **self.kwargs) +class KeyError(builtins.KeyError): + def __str__(self): + return super(Exception, self).__str__() + + class ErrorContext: # Any other threads should get a completely independent _slate. _slate = threading.local() @@ -87,6 +93,9 @@ def decorate_exception(self, cls: type[E], exception: E) -> E: + "\n\nSee if this has been reported at https://github.com/scikit-hep/awkward/issues" ) new_exception.__cause__ = exception + elif issubclass(cls, builtins.KeyError): + new_exception = KeyError(self.format_exception(exception)) + new_exception.__cause__ = exception else: new_exception = cls(self.format_exception(exception)) new_exception.__cause__ = exception