Skip to content

Commit

Permalink
fix: do not pass nil error to error handler (#145)
Browse files Browse the repository at this point in the history
During the previous error handling refactor, we missed some parts where
no error was generated, but still use it.
  • Loading branch information
jooola authored Jan 9, 2024
1 parent 0bc73eb commit e742263
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions builder/hcloud/step_create_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
return errorHandler(state, ui, fmt.Sprintf("Could not fetch SSH key '%s'", k), err)
}
if sshKey == nil {
return errorHandler(state, ui, fmt.Sprintf("Could not find SSH key '%s'", k), err)
return errorHandler(state, ui, "", fmt.Errorf("Could not find SSH key '%s'", k))
}
sshKeys = append(sshKeys, sshKey)
}
Expand Down Expand Up @@ -161,8 +161,7 @@ func (s *stepCreateServer) Cleanup(state multistep.StateBag) {
ui.Say("Destroying server...")
_, _, err := client.Server.DeleteWithResult(context.TODO(), &hcloud.Server{ID: s.serverId})
if err != nil {
ui.Error(fmt.Sprintf(
"Error destroying server. Please destroy it manually: %s", err))
errorHandler(state, ui, "Could not destroy server (please destroy it manually)", err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions builder/hcloud/step_pre_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul
return errorHandler(state, ui, fmt.Sprintf("Could not fetch server type '%s'", c.ServerType), err)
}
if serverType == nil {
return errorHandler(state, ui, fmt.Sprintf("Could not find server type '%s'", c.ServerType), err)
return errorHandler(state, ui, "", fmt.Errorf("Could not find server type '%s'", c.ServerType))
}
state.Put(StateServerType, serverType)

Expand All @@ -39,7 +39,7 @@ func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul
return errorHandler(state, ui, fmt.Sprintf("Could not fetch upgrade server type '%s'", c.UpgradeServerType), err)
}
if serverType == nil {
return errorHandler(state, ui, fmt.Sprintf("Could not find upgrade server type '%s'", c.UpgradeServerType), err)
return errorHandler(state, ui, "", fmt.Errorf("Could not find upgrade server type '%s'", c.UpgradeServerType))
}

if serverType.Architecture != upgradeServerType.Architecture {
Expand Down

0 comments on commit e742263

Please sign in to comment.