From f4934611c4ad5a51d1435713e22194a0229bcf38 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Tue, 12 Nov 2024 21:34:47 -0800 Subject: [PATCH] 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. --- cmd/aepcli/main.go | 4 ++-- internal/service/resource_definition.go | 6 ++---- internal/service/service.go | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/aepcli/main.go b/cmd/aepcli/main.go index 59315fb..65bfd9e 100644 --- a/cmd/aepcli/main.go +++ b/cmd/aepcli/main.go @@ -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 } diff --git a/internal/service/resource_definition.go b/internal/service/resource_definition.go index 5b7811f..cdbd2aa 100644 --- a/internal/service/resource_definition.go +++ b/internal/service/resource_definition.go @@ -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 { diff --git a/internal/service/service.go b/internal/service/service.go index 6349105..392ad96 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -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