Fix panic when error is not *exec.ExitError (Fixes #239)#273
Merged
Conversation
Replace unsafe type assertion when handling process.Wait() errors with errors.As to safely support *exec.ExitError, *os.SyscallError, and wrapped errors. Adds tests to verify exit code propagation and fallback behavior.
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.
This pull request improves error handling in command execution by making the extraction of exit codes from errors more robust and by adding targeted unit tests for this logic. The changes ensure that exit codes are handled correctly for different error types and that the behavior is well-tested.
Error handling improvements:
runCmd(inexec.go) to safely handle errors that may not be of type*exec.ExitError, usingerrors.Asfor type assertion and providing a fallback exit code of 1 for non-standard errors.errorspackage import to support the improved error handling.Testing enhancements:
exec_error_test.gowith unit tests for exit code extraction, including cases for both standard*exec.ExitErrorand generic errors, and introduced a helper functionextractExitCodemirroring the runtime logic.Fixes #239