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

Make subprocess calls raise an exception on non-zero exit codes #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sanqui
Copy link

@Sanqui Sanqui commented Jun 15, 2023

The Python function subprocess.call() does not raise an exception when the command returns a non-zero exit code, i.e. it fails. This function is used in four places, but the most critical one is subprocess.call(["/usr/bin/ditto", f, f_in_image]). If not enough space is allocated for the .dmg, this command will fail and output to stderr,

ditto: /Volumes/Volume 1/foo.bar: No space left on device

Because the return code of this call is not validated, dmgbuild continues merrily, which can cause a broken release when happening as a part of a deployment process.

Replace all subprocess.call() functions with subprocess.check_call() to ensure that an error like this raises an exception and causes the process to fail. subprocess.check_call() is already used in other places in the code.

@Sanqui
Copy link
Author

Sanqui commented Jun 15, 2023

The tests fail, so I checked what gets printed to stderr:

E           subprocess.CalledProcessError: Command '['/usr/bin/ditto', '/System/Applications/TextEdit.app', '/Volumes/Test/TextEdit.app']' returned non-zero exit status 1.

/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py:369: CalledProcessError
------------------------------------------------------ Captured stderr call -------------------------------------------------------
ditto: /Volumes/Test/TextEdit.app/Contents: Operation not permitted

I believe the test was flawed to begin with and my change revealed this issue, but please let me know if I'm wrong -- I don't know much about Mac packaging. In any case, I'm not sure how I would fix the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant