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

Function raise_chained_errors

src/filelock/_core/_errors.py:145–166  ·  view source on GitHub ↗
(first_error: BaseException, second_error: BaseException | None = None)

Source from the content-addressed store, hash-verified

143
144
145def raise_chained_errors(first_error: BaseException, second_error: BaseException | None = None) -> NoReturn:
146 if second_error is None:
147 first_context = first_error.__context__
148 try:
149 raise first_error # ruff:ignore[raise-within-try] # the handler restores caller-supplied context before propagation
150 except BaseException:
151 first_error.__context__ = first_context
152 raise
153 if (second_context := second_error.__context__) is not None and second_context is not first_error:
154 _detach_exception_context(second_context, first_error)
155 append_exception_context(first_error, second_context)
156 first_context = first_error.__context__
157 try:
158 raise first_error # ruff:ignore[raise-within-try] # the second raise needs this error as implicit context
159 except BaseException: # ruff:ignore[blind-except] # first_error may be a control-flow exception
160 first_error.__context__ = first_context
161 try:
162 raise second_error # ruff:ignore[raise-within-try] # the handler makes the chain interpreter-independent
163 except BaseException:
164 second_error.__context__ = first_error
165 first_error.__context__ = first_context
166 raise
167
168
169def _detach_exception_context(error: BaseException, target: BaseException) -> None:

Callers 5

_finish_connectionMethod · 0.90
_acquire_transactionMethod · 0.90
raise_cancelled_errorFunction · 0.90

Calls 2

append_exception_contextFunction · 0.85

Tested by

no test coverage detected