(first_error: BaseException, second_error: BaseException | None = None)
| 143 | |
| 144 | |
| 145 | def 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 | |
| 169 | def _detach_exception_context(error: BaseException, target: BaseException) -> None: |
no test coverage detected