diff --git a/src/monitor_utils/runner.py b/src/monitor_utils/runner.py index 0358772..645601d 100644 --- a/src/monitor_utils/runner.py +++ b/src/monitor_utils/runner.py @@ -553,3 +553,12 @@ async def retry_failed_pages( retry_attempt += 1 return failed_pages + + +def first_error(group_exc: BaseExceptionGroup) -> BaseException: + """Return the first leaf exception of a possibly nested exception group.""" + error = group_exc.exceptions[0] + while isinstance(error, BaseExceptionGroup): + error = error.exceptions[0] + + return error