Skip to content

Commit 05133be

Browse files
tenthirtyamlbajolet-hashicorp
authored andcommitted
fix: improve sata controller error handling
- Utilize `errors.Is` for accurate error comparison when checking for `ErrNoSataController`, allowing for correct handling of wrapped errors. - Implement error wrapping with `%w` in `fmt.Errorf` to preserve underlying error information. - Add handling for unexpected error conditions from `FindSATAController` to ensure robustness. Signed-off-by: Ryan Johnson <[email protected]>
1 parent 01194cd commit 05133be

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

builder/vsphere/common/step_add_cdrom.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package common
88

99
import (
1010
"context"
11+
"errors"
1112
"fmt"
1213

1314
"github.com/hashicorp/packer-plugin-sdk/multistep"
@@ -81,10 +82,15 @@ func (s *StepAddCDRom) Run(_ context.Context, state multistep.StateBag) multiste
8182
vm := state.Get("vm").(driver.VirtualMachine)
8283

8384
if s.Config.CdromType == "sata" {
84-
if _, err := vm.FindSATAController(); err == driver.ErrNoSataController {
85+
if _, err := vm.FindSATAController(); err != nil {
86+
if !errors.Is(err, driver.ErrNoSataController) {
87+
state.Put("error", fmt.Errorf("unexpected error finding SATA controller: %w", err))
88+
return multistep.ActionHalt
89+
}
90+
8591
ui.Say("Adding SATA controller...")
8692
if err := vm.AddSATAController(); err != nil {
87-
state.Put("error", fmt.Errorf("error adding SATA controller: %v", err))
93+
state.Put("error", fmt.Errorf("error adding SATA controller: %w", err))
8894
return multistep.ActionHalt
8995
}
9096
}

0 commit comments

Comments
 (0)