-
Committer:
Simon Chopin
-
Author(s):
Benjamin Drung
-
Date:
2023-04-28 08:41:28 UTC
-
Revision ID:
git-v1:81fad6cf9323eadaf21f5215a139ba12df98d9e5
fix: Fix raising OSError if _command_output() runs into a timeout
mypy complains:
```
apport/report.py:179: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior [str-bytes-safe]
apport/report.py:180: error: Item "None" of "Optional[bytes]" has no attribute "rstrip" [union-attr]
```
The mypy complains can be converted into a test case that fail:
```
ERROR: test_command_output_timeout_no_output (tests.integration.test_report.T.test_command_output_timeout_no_output)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/bdrung/projects/apport/apport/apport/report.py", line 169, in _command_output
sp = subprocess.run(
^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 550, in run
stdout, stderr = process.communicate(input, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 1207, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 2060, in _communicate
self._check_timeout(endtime, orig_timeout, stdout, stderr)
File "/usr/lib/python3.11/subprocess.py", line 1251, in _check_timeout
raise TimeoutExpired(
subprocess.TimeoutExpired: Command '['sleep', '3600']' timed out after 0.1 seconds
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/bdrung/projects/apport/apport/tests/integration/test_report.py", line 1938, in test_command_output_timeout_no_output
apport.report._command_output(["sleep", "3600"], timeout=0.1)
File "/home/bdrung/projects/apport/apport/apport/report.py", line 182, in _command_output
f" after {error.timeout} seconds: {error.stdout.rstrip()}"
^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'rstrip'
```
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>