Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle CalledProcessError when calling uname #371

Merged

Conversation

dieresys
Copy link

Usually, when distro is used in Windows, it returns nothing. Any call to lsb_release, uname, etc, raises a [[WinError 2] The system cannot find the file specified error, which is properly handled. However, in a particular environment where I've run it, I've found that the call to uname raises a CalledProcessError, because a Policy or a Security Control is injecting a non-zero return code:

t=2024-10-04T15:13:39+0200  Command '('uname', '-rs')' returned non-zero exit status 3221225794.
Traceback (most recent call last):
  File "C:\...\main.py", line 123, in __check_supported_platform
    distro_id = distro.id()
                ^^^^^^^^^^^
  File "C:\...\site-packages\distro\distro.py", line 284, in id
    return _distro.id()
           ^^^^^^^^^^^^
  File "C:\...\site-packages\distro\distro.py", line 855, in id
    distro_id = self.uname_attr("id")
                ^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\site-packages\distro\distro.py", line 1088, in uname_attr
    return self._uname_info.get(attribute, "")
           ^^^^^^^^^^^^^^^^
  File "C:\...\lib\functools.py", line 995, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "C:\...\site-packages\distro\distro.py", line 1202, in _uname_info
    stdout = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\lib\subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\lib\subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('uname', '-rs')' returned non-zero exit status 3221225794.

We do handle CalledProcessError in other calls, so I'm adding it to uname too.

Usually, when `distro` is used in Windows, it returns nothing. Any call to `lsb_release`, `uname', etc, raises a `[[WinError 2] The system cannot find the file specified` error, which is properly handled.
However, in a particular environment where I've run it, I've found that the call to `uname` raises a `CalledProcessError`, because a Policy or a Security Control is injecting a non-zero return code:

```
t=2024-10-04T15:13:39+0200  Command '('uname', '-rs')' returned non-zero exit status 3221225794.
Traceback (most recent call last):
  File "C:\...\main.py", line 123, in __check_supported_platform
    distro_id = distro.id()
                ^^^^^^^^^^^
  File "C:\...\site-packages\distro\distro.py", line 284, in id
    return _distro.id()
           ^^^^^^^^^^^^
  File "C:\...\site-packages\distro\distro.py", line 855, in id
    distro_id = self.uname_attr("id")
                ^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\site-packages\distro\distro.py", line 1088, in uname_attr
    return self._uname_info.get(attribute, "")
           ^^^^^^^^^^^^^^^^
  File "C:\...\lib\functools.py", line 995, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "C:\...\site-packages\distro\distro.py", line 1202, in _uname_info
    stdout = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\lib\subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\lib\subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('uname', '-rs')' returned non-zero exit status 3221225794.
```

We do handle `CalledProcessError` in other calls, so I'm adding to
`uname` too.
@HorlogeSkynet HorlogeSkynet self-assigned this Oct 26, 2024
@HorlogeSkynet HorlogeSkynet added this to the v1.11.0 milestone Oct 26, 2024
@HorlogeSkynet HorlogeSkynet merged commit 3bd19e6 into python-distro:master Oct 26, 2024
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants