Skip to content

Commit

Permalink
Report action cleanup errors
Browse files Browse the repository at this point in the history
Currently any errors from the cleanup of an action are
discarded and not reported to the user. So let's report
errors during the cleanup to the user and indicate that
the overall execution actually failed by setting the
exitcode appropriately.

Signed-off-by: Christopher Obbard <[email protected]>
  • Loading branch information
obbardc committed Jul 26, 2023
1 parent 2810962 commit 062a55d
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions cmd/debos/debos.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ func handleError(context *debos.DebosContext, err error, a debos.Action, stage s
return true
}

func do_run(r actions.Recipe, context *debos.DebosContext) bool {
func do_run(r actions.Recipe, context *debos.DebosContext) (success bool) {
for _, a := range r.Actions {
err := a.Run(context)

// This does not stop the call of stacked Cleanup methods for other Actions
// Stack Cleanup methods
defer a.Cleanup(context)
/* Cleanup after all actions which attempted to run, even if the
* previous cleanup failed. Fail on any errors produced during cleanup,
* but allow all actions to cleanup before failing. */
defer func(action debos.Action) {
err := action.Cleanup(context)

if handleError(context, err, action, "Cleanup") {
success = false
}
}(a)

// Check the state of Run method
if handleError(context, err, a, "Run") {
Expand Down Expand Up @@ -307,7 +314,12 @@ func main() {

for _, a := range r.Actions {
// Stack PostMachineCleanup methods
defer a.PostMachineCleanup(&context)
defer func(action debos.Action) {
err := action.PostMachineCleanup(&context)

// report errors but do not stop execution
handleError(&context, err, action, "PostMachineCleanup")
}(a)

err = a.PreMachine(&context, m, &args)
if handleError(&context, err, a, "PreMachine") {
Expand Down Expand Up @@ -342,7 +354,12 @@ func main() {
if !fakemachine.InMachine() {
for _, a := range r.Actions {
// Stack PostMachineCleanup methods
defer a.PostMachineCleanup(&context)
defer func(action debos.Action) {
err := action.PostMachineCleanup(&context)

// report errors but do not stop execution
handleError(&context, err, action, "PostMachineCleanup")
}(a)

err = a.PreNoMachine(&context)
if handleError(&context, err, a, "PreNoMachine") {
Expand Down

0 comments on commit 062a55d

Please sign in to comment.