MCPcopy Create free account
hub / github.com/tox-dev/filelock / _raise_chained_errors

Function _raise_chained_errors

src/filelock/_api.py:246–267  ·  view source on GitHub ↗
(first_error: BaseException, second_error: BaseException | None = None)

Source from the content-addressed store, hash-verified

244
245
246def _raise_chained_errors(first_error: BaseException, second_error: BaseException | None = None) -> NoReturn:
247 if second_error is None:
248 first_context = first_error.__context__
249 try:
250 raise first_error # ruff:ignore[raise-within-try] # the handler restores caller-supplied context before propagation
251 except BaseException:
252 first_error.__context__ = first_context
253 raise
254 if (second_context := second_error.__context__) is not None and second_context is not first_error:
255 _detach_exception_context(second_context, first_error)
256 _append_exception_context(first_error, second_context)
257 first_context = first_error.__context__
258 try:
259 raise first_error # ruff:ignore[raise-within-try] # the second raise needs this error as implicit context
260 except BaseException: # ruff:ignore[blind-except] # first_error may be a control-flow exception
261 first_error.__context__ = first_context
262 try:
263 raise second_error # ruff:ignore[raise-within-try] # the handler makes the chain interpreter-independent
264 except BaseException:
265 second_error.__context__ = first_error
266 first_error.__context__ = first_context
267 raise
268
269
270def _detach_exception_context(error: BaseException, target: BaseException) -> None:

Callers 5

_do_acquire_innerMethod · 0.85
_finish_connectionMethod · 0.85
_raise_cancelled_errorFunction · 0.85

Calls 2

Tested by

no test coverage detected