bootstrap: Don't catch Ctrl-C (#41449)
This commit is contained in:
parent
90aee11c33
commit
8ce110e069
@ -1047,9 +1047,9 @@ def __bool__(self):
|
||||
"""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:
|
||||
|
@ -386,7 +386,7 @@ def ensure_module_importable_or_raise(module: str, abstract_spec: Optional[str]
|
||||
exception_handler = GroupedExceptionHandler()
|
||||
|
||||
for current_config in bootstrapping_sources():
|
||||
with exception_handler.forward(current_config["name"]):
|
||||
with exception_handler.forward(current_config["name"], Exception):
|
||||
source_is_enabled_or_raise(current_config)
|
||||
current_bootstrapper = create_bootstrapper(current_config)
|
||||
if current_bootstrapper.try_import(module, abstract_spec):
|
||||
@ -441,7 +441,7 @@ def ensure_executables_in_path_or_raise(
|
||||
exception_handler = GroupedExceptionHandler()
|
||||
|
||||
for current_config in bootstrapping_sources():
|
||||
with exception_handler.forward(current_config["name"]):
|
||||
with exception_handler.forward(current_config["name"], Exception):
|
||||
source_is_enabled_or_raise(current_config)
|
||||
current_bootstrapper = create_bootstrapper(current_config)
|
||||
if current_bootstrapper.try_search_path(executables, abstract_spec):
|
||||
|
@ -321,3 +321,18 @@ def inner():
|
||||
"""
|
||||
).format(__file__)
|
||||
)
|
||||
|
||||
|
||||
def test_grouped_exception_base_type():
|
||||
h = llnl.util.lang.GroupedExceptionHandler()
|
||||
|
||||
with h.forward("catch-runtime-error", RuntimeError):
|
||||
raise NotImplementedError()
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
with h.forward("catch-value-error", ValueError):
|
||||
raise NotImplementedError()
|
||||
|
||||
message = h.grouped_message(with_tracebacks=False)
|
||||
assert "catch-runtime-error" in message
|
||||
assert "catch-value-error" not in message
|
||||
|
Loading…
Reference in New Issue
Block a user