Skip to content

Commit

Permalink
fix: better error messages when not passing an id
Browse files Browse the repository at this point in the history
not passing an id for a resource that requires it results
in an esoteric error message.
  • Loading branch information
toumorokoshi committed Nov 13, 2024
1 parent 2c10a39 commit f493461
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/aepcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func aepcli(args []string) error {
s = service.NewService(api, headersMap)

result, err := s.ExecuteCommand(additionalArgs)
fmt.Println(result)
if err != nil {
return fmt.Errorf("unable to execute command: %w", err)
return err
}
fmt.Println(result)
return nil
}

Expand Down
6 changes: 2 additions & 4 deletions internal/service/resource_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,13 @@ func ExecuteResourceCommand(r *api.Resource, args []string) (*http.Request, stri
}
c.AddCommand(customCmd)
}
var stderr strings.Builder
var stdout strings.Builder
c.SetOut(&stdout)
c.SetErr(&stderr)
c.SetArgs(args)
if err := c.Execute(); err != nil {
return nil, stdout.String() + stderr.String(), err
return nil, stdout.String(), err
}
return req, stdout.String() + stderr.String(), err
return req, stdout.String(), err
}

func addSchemaFlags(c *cobra.Command, schema openapi.Schema, args map[string]interface{}) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *Service) ExecuteCommand(args []string) (string, error) {
}
req, output, err := ExecuteResourceCommand(r, args[1:])
if err != nil {
return "", fmt.Errorf("unable to execute command: %v", err)
return output, err
}
if req == nil {
return output, nil
Expand Down

0 comments on commit f493461

Please sign in to comment.