Skip to content

Comments

Fix panic when error is not *exec.ExitError (Fixes #239)#273

Merged
jwilder merged 1 commit intomasterfrom
fix-239-exiterror-panic
Feb 23, 2026
Merged

Fix panic when error is not *exec.ExitError (Fixes #239)#273
jwilder merged 1 commit intomasterfrom
fix-239-exiterror-panic

Conversation

@jwilder
Copy link
Owner

@jwilder jwilder commented Feb 23, 2026

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:

  • Refactored the exit code extraction logic in runCmd (in exec.go) to safely handle errors that may not be of type *exec.ExitError, using errors.As for type assertion and providing a fallback exit code of 1 for non-standard errors.
  • Added the errors package import to support the improved error handling.

Testing enhancements:

  • Added a new file exec_error_test.go with unit tests for exit code extraction, including cases for both standard *exec.ExitError and generic errors, and introduced a helper function extractExitCode mirroring the runtime logic.

Fixes #239

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.
@jwilder jwilder merged commit ccb5186 into master Feb 23, 2026
1 check passed
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.

panic: interface conversion: error is *os.SyscallError, not *exec.ExitError

1 participant