diff --git a/internal/statemachine/classic_states.go b/internal/statemachine/classic_states.go index c21b2755..a7fc32a7 100644 --- a/internal/statemachine/classic_states.go +++ b/internal/statemachine/classic_states.go @@ -687,14 +687,9 @@ func (stateMachine *StateMachine) installPackages() error { } } defer func(cmds []*exec.Cmd) { - if tmpErr := runAll(cmds); tmpErr != nil { - if err != nil { - err = fmt.Errorf("%s after previous error: %w", tmpErr, err) - } else { - err = tmpErr - } - } + _ = runAll(cmds) }(umountCmds) + installPackagesCmds = append(installPackagesCmds, mountCmds...) umounts = append(umounts, umountCmds...) } @@ -1165,7 +1160,6 @@ func (stateMachine *StateMachine) prepareClassicImage() error { // preseedClassicImage preseeds the snaps that have already been staged in the chroot func (stateMachine *StateMachine) preseedClassicImage() error { - var err error classicStateMachine := stateMachine.parent.(*ClassicStateMachine) // create some directories in the chroot that we will bind mount from the @@ -1190,19 +1184,14 @@ func (stateMachine *StateMachine) preseedClassicImage() error { var umountCmds []*exec.Cmd for _, mountPoint := range mountPoints { thisMountCmds, thisUmountCmds := mountFromHost(stateMachine.tempDirs.chroot, mountPoint) - defer func(cmds []*exec.Cmd) { - if tmpErr := runAll(cmds); tmpErr != nil { - if err != nil { - err = fmt.Errorf("%s after previous error: %w", tmpErr, err) - } else { - err = tmpErr - } - } - }(umountCmds) mountCmds = append(mountCmds, thisMountCmds...) umountCmds = append(umountCmds, thisUmountCmds...) } + defer func(cmds []*exec.Cmd) { + _ = runAll(cmds) + }(umountCmds) + // assemble the commands in the correct order: mount, preseed, unmount preseedCmds = append(preseedCmds, mountCmds...) preseedCmds = append(preseedCmds, diff --git a/internal/statemachine/classic_test.go b/internal/statemachine/classic_test.go index 8d86bf31..7b57e021 100644 --- a/internal/statemachine/classic_test.go +++ b/internal/statemachine/classic_test.go @@ -2062,13 +2062,7 @@ func TestSuccessfulClassicRun(t *testing.T) { mountImageCmds = append(mountImageCmds, mountCmds...) umountImageCmds = append(umountImageCmds, umountCmds...) defer func(cmds []*exec.Cmd) { - if tmpErr := runAll(cmds); tmpErr != nil { - if err != nil { - err = fmt.Errorf("%s after previous error: %w", tmpErr, err) - } else { - err = tmpErr - } - } + _ = runAll(cmds) }(umountCmds) } // make sure to unmount the disk too diff --git a/internal/statemachine/helper.go b/internal/statemachine/helper.go index 5414ee69..b75b185a 100644 --- a/internal/statemachine/helper.go +++ b/internal/statemachine/helper.go @@ -1024,13 +1024,7 @@ func (stateMachine *StateMachine) updateGrub(rootfsVolName string, rootfsPartNum updateGrubCmds = append(updateGrubCmds, mountCmds...) umounts = append(umounts, umountCmds...) defer func(cmds []*exec.Cmd) { - if tmpErr := runAll(cmds); tmpErr != nil { - if err != nil { - err = fmt.Errorf("Unable to unmount: %s after previous error: %w", tmpErr, err) - } else { - err = tmpErr - } - } + _ = runAll(cmds) }(umountCmds) } @@ -1082,13 +1076,7 @@ func (stateMachine *StateMachine) updateGrub(rootfsVolName string, rootfsPartNum loopUsed, ) defer func() { - if tmpErr := teardownCmd.Run(); tmpErr != nil { - if err != nil { - err = fmt.Errorf("Unable to execute teardown cmd: %s after previous error: %w", tmpErr, err) - } else { - err = tmpErr - } - } + _ = teardownCmd.Run() }() updateGrubCmds = append(updateGrubCmds, teardownCmd) diff --git a/internal/statemachine/helper_test.go b/internal/statemachine/helper_test.go index 5b2a91fe..2ba41e05 100644 --- a/internal/statemachine/helper_test.go +++ b/internal/statemachine/helper_test.go @@ -1377,7 +1377,6 @@ func TestFailedUpdateGrub(t *testing.T) { asserter.AssertErrContains(err, "Error running command") // check defered function failed and wrapped the error asserter.AssertErrContains(err, "Unable to execute teardown cmd") - asserter.AssertErrContains(err, "Unable to unmount") execCommand = exec.Command }) }