fix: exit codes for indirect tasks #1270
Merged
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 #1266
This bug is happening because when we run a command, we are always wrapping the
interp.exitStatus
error and returning aTaskRunError
:task/task.go
Lines 232 to 243 in 7e7a016
This works fine at the top-level (for direct calls) because we can simply unwrap the error in Task's main function:
task/cmd/task/task.go
Lines 84 to 87 in 7e7a016
However, when we run a command indirectly via another task, we are wrapping the
TaskRunError
in anotherTaskRunError
. This problem is recursive and means that we can't effectively unwrap the error to get the exit code out.The solution to this is simply to check if the command is being called directly and if not, we return the
interp.exitStatus
directly instead of wrapping it up. This means that we only wrap once on the top-level error and unwrapping in the main function just works.I've also updated the tests to cover this case.