diff --git a/.vscode/launch.json b/.vscode/launch.json index a5e40d406..f28e013ab 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -51,6 +51,18 @@ "kafka", "list" ] + }, + { + "name": "Describe Kafka", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/cmd/rhoas", + "env": {}, + "args": [ + "kafka", + "describe" + ] } ] } \ No newline at end of file diff --git a/cmd/rhoas/main.go b/cmd/rhoas/main.go index 7a71b52e2..0ecf0a143 100644 --- a/cmd/rhoas/main.go +++ b/cmd/rhoas/main.go @@ -1,9 +1,12 @@ package main import ( + "errors" "fmt" "os" + "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/api/managedservices" + "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmd/root" "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/config" "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/version" @@ -26,9 +29,25 @@ func main() { generateDocumentation(rootCmd) } - if err := rootCmd.Execute(); err != nil { - fmt.Fprintf(os.Stderr, "Error: %v\n", err) + err := rootCmd.Execute() + if err == nil { + return + } + + // Attempt to unwrap the descriptive API error message + var apiError managedservices.GenericOpenAPIError + if ok := errors.As(err, &apiError); ok { + errModel := apiError.Model() + + e, ok := errModel.(managedservices.Error) + if ok { + fmt.Fprintf(os.Stderr, "Error: %v\n", e.Reason) + os.Exit(1) + } } + + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) } func initConfig() {