-
Notifications
You must be signed in to change notification settings - Fork 213
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
exec mixin should allow certain commands to have non-zero exit codes #592
Comments
Yes! Please! And not just for |
Thanks for letting us know that this would be helpful! Most of the mixins use exec as a base, so they can pick up the feature once we release it in the exec mixin. I'll make sure when we do this to update every mixin that can support it. |
I also would like this convenient feature. Since it can be useful in some cases. I encountered the problem recently, right now I can fix it by using a script that does the trick for me (aka always sending back a zero exit code). But it could be much more convenient to directly have access to this feature from porter.yaml file. |
If anyone is interested in implementing this, the change can be made against the main branch (it doesn't have to wait for v1). The relevant code is in the get.porter.sh/pkg/exec/builder package, mainly in action.go, which is shared with all the other mixins. We should define an interface that any mixin can implement that lets the mixin decide if it wants to ignore the error or not from a command. type HasErrorHandling interface {
IsFatalError(exitCode int, output string) bool
} Mixins can use whatever logic they like then to evaluate the exit code, output and the command executed to decide if the error should cause the bundle to stop execution. We may want to provide reusable structs and functions for common error handling, similar to what we do for outputs, so that mixins don't have to implement the interface from scratch and have some consistency between mixins. |
Add the HasErrorHandling interface to the shared pkg/exec/builder package used by all the mixins. When implemented, a mixin can examine a failed command and optionaly handle it. The exec mixin now supports ignoring failed commands, which demonstrates how to use builder.IgnoreErrorHandler struct to use the same error handling behavior. Closes getporter#592 Signed-off-by: Carolyn Van Slyck <[email protected]>
Add the HasErrorHandling interface to the shared pkg/exec/builder package used by all the mixins. When implemented, a mixin can examine a failed command and optionaly handle it. The exec mixin now supports ignoring failed commands, which demonstrates how to use builder.IgnoreErrorHandler struct to use the same error handling behavior. Closes getporter#592 Signed-off-by: Carolyn Van Slyck <[email protected]>
Add the HasErrorHandling interface to the shared pkg/exec/builder package used by all the mixins. When implemented, a mixin can examine a failed command and optionaly handle it. The exec mixin now supports ignoring failed commands, which demonstrates how to use builder.IgnoreErrorHandler struct to use the same error handling behavior. Closes getporter#592 Signed-off-by: Carolyn Van Slyck <[email protected]>
* sync go mod Signed-off-by: Carolyn Van Slyck <[email protected]> * Allow mixins to ignore a failed command Add the HasErrorHandling interface to the shared pkg/exec/builder package used by all the mixins. When implemented, a mixin can examine a failed command and optionaly handle it. The exec mixin now supports ignoring failed commands, which demonstrates how to use builder.IgnoreErrorHandler struct to use the same error handling behavior. Closes #592 Signed-off-by: Carolyn Van Slyck <[email protected]>
Implemented in #1846 |
Sometimes a command is allowed to have a non-zero exit code. For example when deleting a resource that is already gone, our mixins check for the "not found" text on stdout and then continue gracefully.
Ignore a non-zero exit code when stderr/stdout contains a message
Ignore a non-zero exit code when stderr/stdout matches a regular expression
Ignore some exit codes
Ignore all non-zero exit codes
If we make the change to the our mixin framework directly (which a lot of mixins use), then other mixins besides the exec mixin can update and get this feature for free too
porter/pkg/exec/builder/execute.go
Lines 145 to 148 in 5efddb8
This should include test cases for gracefully handling errors, either in execute_test.go or in the exec mixins tests, whichever is easier to add a new test for. I don't believe we have an existing test that you can modify.
It's totally fine to just implement a single use case listed here. The best one to start with is ignoring all errors (last use case).
The text was updated successfully, but these errors were encountered: