Repository navigation
Stop shell_command from swallowing exceptions in bin/docker-to-squash.py - #9297
Closed
ToniAdreal wants to merge 1 commit into
Closed
ToniAdreal wants to merge 1 commit into
ToniAdreal wants to merge 1 commit into
Conversation
The return statement in the finally clause of shell_command discards every exception raised in the try/except blocks, so raise_on_error=True never raises: a failing command returns its return code and a command that cannot be started returns (None, None, -1). Move the return below the try/except/finally so exceptions propagate and only the timer cleanup stays in finally. Call sites that pass raise_on_error=True either ignore the result or already expect an exception (check_dependencies wraps each call in try/except and could never detect a missing dependency before this change). Update test_shell_command to assert that failures raise. Signed-off-by: ToniAdreal <184365500+ToniAdreal@users.noreply.github.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9289.
shell_commandinbin/docker-to-squash.pyreturns from itsfinallyclause, which discards every exception raised in thetry/exceptblocks. Soraise_on_error=Truenever raises. Reproduced on Python 3.12.3:shell_command(["false"], False, False, True)returns(b'', b'', 1)instead of raising.shell_command(["badcmd"], False, False, True)returns(None, None, -1); even thePopenfailure is swallowed.The fix moves the
returnbelow thetry/except/finally, keeping only the timer cleanup infinally, so exceptions propagate again.Call-site audit for
raise_on_error=True: the direct callers (skopeo copy,tar,setfattr,mknod,chown,rm,mksquashfs, thehdfs_*wrappers) either ignore the return value or pass the flag through from callers that do.check_dependencieswraps each probe intry/exceptand returns 1 on failure; with the swallowed exceptions it could never detect a missing dependency, and it works as written after this change (verified locally: it now reports the missinghadoopbinary and returns 1). Success-path behavior is unchanged: withraise_on_error=False, a failing command still returns(out, err, rc).test_shell_commandencoded the bug as its contract (the failure case only assertedrc != 0); it now asserts that a command that cannot be started and a command exiting non-zero both raise whenraise_on_erroris set.Testing note: the test suite cannot be imported on Python 3.10+ until the compatibility fix in the #9291 PR lands, so locally I verified this change two ways: on top of that PR's branch, where
python3 -m unittest test_docker_to_squash.pypasses as-is, and against this exact tree with only thecollections.abcimport shimmed in a scratch copy (the one-line change from that PR), where the updated test also passes and the repro cases above raise as expected.This is one of the four docker-to-squash.py fixes #9284 left to separate PRs.