python / python/cpython

tarfile.TarFile.next() adds an unnecessary traceback frame when reraising exceptions

Open
#149,760 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

description:

https://gist.github.com/devdanzin/f8af359770ff200eac8474de5644be82

tarfile.TarFile.next() currently reraises non-zlib exceptions with raise e
inside its generic exception handler:

except Exception as e:
    try:
        import zlib
        if isinstance(e, zlib.error):
            raise ReadError(f'zlib error: {e}') from None
        else:
            raise e
    except ImportError:
        raise e

Using raise e adds an extra traceback frame at the re-raise site. A bare
raise would keep the traceback cleaner while preserving the original exception
and its traceback.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Windows

Linked PRs
  • gh-149761
  • gh-157257

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the tarfile module for TarFile.next() and inspect the generic exception handler shown in the issue. Confirm the traceback difference described in the linked gist, then run the tarfile tests after the exception-handling change to verify that non-zlib exceptions retain their original traceback and zlib errors remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.