apport_python_hook: FileNotFoundError if cwd was deleted

Bug #1979637 reported by Benjamin Drung
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Apport
Fix Released
Low
Unassigned
apport (Ubuntu)
Fix Released
Undecided
Unassigned
Jammy
New
Undecided
Unassigned

Bug Description

Test Case
---------

Run following shell script:

```sh
echo "raise ValueError()" > /tmp/failure.py
mkdir /tmp/foo
cd /tmp/foo/
rmdir /tmp/foo/
python3 ../failure.py
```

It should only print following stacktrace:

```
Traceback (most recent call last):
  File "../failure.py", line 1, in <module>
    raise ValueError()
ValueError
```

Regression Potential
--------------------

There might be a regression that causes capturing Python exception fail. Then reporting them as bugs to Launchpad or the error tracker would not be possible.

Original Description
--------------------

The script should only show a ValueError, but apport_python_hook.py crashes:

```
Traceback (most recent call last):
  File "../failure.py", line 1, in <module>
    raise ValueError()
ValueError
Error in sys.excepthook:
Traceback (most recent call last):
  File "<frozen importlib._bootstrap_external>", line 1372, in _path_importer_cache
KeyError: '..'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 55, in apport_excepthook
    import apt_pkg
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 945, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1439, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1408, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1374, in _path_importer_cache
  File "<frozen importlib._bootstrap_external>", line 1350, in _path_hooks
  File "<frozen importlib._bootstrap_external>", line 1632, in path_hook_for_FileFinder
  File "<frozen importlib._bootstrap_external>", line 1505, in __init__
FileNotFoundError: [Errno 2] No such file or directory

Original exception was:
Traceback (most recent call last):
  File "../failure.py", line 1, in <module>
    raise ValueError()
ValueError
```

Benjamin Drung (bdrung)
Changed in apport:
status: New → Triaged
milestone: none → 2.22.0
importance: Undecided → Low
Revision history for this message
Benjamin Drung (bdrung) wrote :
Changed in apport:
status: Triaged → Fix Committed
Benjamin Drung (bdrung)
Changed in apport:
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apport - 2.22.0-0ubuntu1

---------------
apport (2.22.0-0ubuntu1) kinetic; urgency=medium

  * New upstream release:
    - Replace `ProblemReport.get_date` by `ProblemReport.get_timestamp`, fixes
      regression in 2.21.0 (LP: #1978487)
    - apport-gtk: Exclude trailing dot from URL links (LP: #1978301)
    - Fix `AttributeError`: 'NoneType' object has no attribute 'write', fixes
      regression in 2.21.0 (LP: #1979211)
    - apport_python_hook: Properly handle missing modules (LP: #1774843)
    - apport_python_hook: Fix FileNotFoundError if the current directory was
      deleted (LP: #1979637)
    - apport_python_hook: Fix crash if os.getcwd() fails (LP: #1977954)
    - Replace deprecated 'imp' module (LP: #1947425)
    - whoopsie-upload-all: Fix 'EOFError' object has no attribute 'errno',
      fixes regression in 2.21.0 (LP: #1979681)
  * Fix KeyError: 'CasperMD5json'

 -- Benjamin Drung <email address hidden> Mon, 27 Jun 2022 12:03:00 +0200

Changed in apport (Ubuntu):
status: New → Fix Released
Benjamin Drung (bdrung)
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers