Error handling for TarFile.extractall currently allows relatively little control over individual issues. Using errorlevel you can ignore “fatal” or “non-fatal” errors, and using debug you can optionally log ignored ones to sys.stderr. If an error is not ignored, it is raised, which aborts the extraction. So, you can’t extract as much as possible and get structured information about what failed.
This sounds like a good use case for exception groups.
My idea for an API:
-
errorlevel=3turns on exception group reporting: allExceptionerrors from extracting individual members are collected, and (if any are found) raised in an ExceptionGroup when the extraction finishes. -
ExtractErrorgains amemberattribute, which contains theTarInfoobject for the failed entry - All other exceptions are “wrapped” in
ExtractError, so that thismemberis always accessible:ExtractErrorgains aexceptionattribute, which contains the exception. In some current cases whereExtractErroris raised, we’ll need to create an appropriate exception to put here.
If you (yes you!) want to add this to Python 3.13, I can help.
The alternative to wrapping everything in ExtractError is to subclass ExceptionGroup to expose the member <-> error relation in another way. This was discussed in bpo-90589 and discussions leading up to it. But I think wrapping is easier.