diff options
Diffstat (limited to 'lib/spack/llnl/util/lang.py')
-rw-r--r-- | lib/spack/llnl/util/lang.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py index 607b093de8..796aecc502 100644 --- a/lib/spack/llnl/util/lang.py +++ b/lib/spack/llnl/util/lang.py @@ -1047,9 +1047,9 @@ class GroupedExceptionHandler: """Whether any exceptions were handled.""" return bool(self.exceptions) - def forward(self, context: str) -> "GroupedExceptionForwarder": + def forward(self, context: str, base: type = BaseException) -> "GroupedExceptionForwarder": """Return a contextmanager which extracts tracebacks and prefixes a message.""" - return GroupedExceptionForwarder(context, self) + return GroupedExceptionForwarder(context, self, base) def _receive_forwarded(self, context: str, exc: Exception, tb: List[str]): self.exceptions.append((context, exc, tb)) @@ -1072,15 +1072,18 @@ class GroupedExceptionForwarder: """A contextmanager to capture exceptions and forward them to a GroupedExceptionHandler.""" - def __init__(self, context: str, handler: GroupedExceptionHandler): + def __init__(self, context: str, handler: GroupedExceptionHandler, base: type): self._context = context self._handler = handler + self._base = base def __enter__(self): return None def __exit__(self, exc_type, exc_value, tb): if exc_value is not None: + if not issubclass(exc_type, self._base): + return False self._handler._receive_forwarded(self._context, exc_value, traceback.format_tb(tb)) # Suppress any exception from being re-raised: |