Skip to content

Commit

Permalink
refactor(iam-key): add proper error message
Browse files Browse the repository at this point in the history
  • Loading branch information
mlec1 committed Nov 1, 2024
1 parent 401a0f8 commit 7248acf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions cmd/ssh_key_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,24 @@ func (c *computeSSHKeyDeleteCmd) cmdRun(_ *cobra.Command, _ []string) error {
}
}

return decorateAsyncOperations(fmt.Sprintf("Deleting SSH key %s...", c.Name), func() error {
err := decorateAsyncOperations(fmt.Sprintf("Deleting SSH key %s...", c.Name), func() error {
op, err := globalstate.EgoscaleV3Client.DeleteSSHKey(ctx, c.Name)
if err != nil {
return err
return fmt.Errorf("exoscale: error while deleting SSH key: %w", err)
}

_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
return err
if err != nil {
return fmt.Errorf("exoscale: error while waiting for SSH key deletion: %w", err)
}

return nil
})
if err != nil {
return err
}

return nil
}

func init() {
Expand Down
8 changes: 6 additions & 2 deletions cmd/ssh_key_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ func (c *computeSSHKeyRegisterCmd) cmdRun(cmd *cobra.Command, _ []string) error
err = decorateAsyncOperations(fmt.Sprintf("Registering SSH key %q...", c.Name), func() error {
op, err := client.RegisterSSHKey(ctx, registerKeyRequest)
if err != nil {
return err
return fmt.Errorf("exoscale: error while registering SSH key: %w", err)
}

_, err = client.Wait(ctx, op, v3.OperationStateSuccess)
return err
if err != nil {
return fmt.Errorf("exoscale: error while waiting for SSH key registration: %w", err)
}

return nil
})
if err != nil {
return err
Expand Down

0 comments on commit 7248acf

Please sign in to comment.