Skip to content

Commit f493461

Browse files
committed
fix: better error messages when not passing an id
not passing an id for a resource that requires it results in an esoteric error message.
1 parent 2c10a39 commit f493461

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

cmd/aepcli/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ func aepcli(args []string) error {
112112
s = service.NewService(api, headersMap)
113113

114114
result, err := s.ExecuteCommand(additionalArgs)
115+
fmt.Println(result)
115116
if err != nil {
116-
return fmt.Errorf("unable to execute command: %w", err)
117+
return err
117118
}
118-
fmt.Println(result)
119119
return nil
120120
}
121121

internal/service/resource_definition.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,13 @@ func ExecuteResourceCommand(r *api.Resource, args []string) (*http.Request, stri
158158
}
159159
c.AddCommand(customCmd)
160160
}
161-
var stderr strings.Builder
162161
var stdout strings.Builder
163162
c.SetOut(&stdout)
164-
c.SetErr(&stderr)
165163
c.SetArgs(args)
166164
if err := c.Execute(); err != nil {
167-
return nil, stdout.String() + stderr.String(), err
165+
return nil, stdout.String(), err
168166
}
169-
return req, stdout.String() + stderr.String(), err
167+
return req, stdout.String(), err
170168
}
171169

172170
func addSchemaFlags(c *cobra.Command, schema openapi.Schema, args map[string]interface{}) error {

internal/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *Service) ExecuteCommand(args []string) (string, error) {
3939
}
4040
req, output, err := ExecuteResourceCommand(r, args[1:])
4141
if err != nil {
42-
return "", fmt.Errorf("unable to execute command: %v", err)
42+
return output, err
4343
}
4444
if req == nil {
4545
return output, nil

0 commit comments

Comments
 (0)