From 18f77bb509d2a083b0ed914c8ba04d7542c7645f Mon Sep 17 00:00:00 2001 From: Jiri Tyr Date: Fri, 23 Apr 2021 14:28:05 +0100 Subject: [PATCH] Make error message more verbose --- pkg/apikey/apikeyCreate.go | 3 +-- pkg/apikey/apikeyDelete.go | 3 +-- pkg/apikey/apikeyList.go | 5 ++--- pkg/grafana/apikey/apikeyCreate.go | 3 +-- pkg/grafana/apikey/apikeyDelete.go | 4 ++-- pkg/grafana/apikey/apikeyList.go | 3 +-- pkg/grafana/grafanaRestart.go | 3 +-- pkg/stack/stackCreate.go | 3 +-- pkg/stack/stackDelete.go | 3 +-- pkg/stack/stackList.go | 5 ++--- 10 files changed, 13 insertions(+), 22 deletions(-) diff --git a/pkg/apikey/apikeyCreate.go b/pkg/apikey/apikeyCreate.go index 4f81f0b..9ffe239 100644 --- a/pkg/apikey/apikeyCreate.go +++ b/pkg/apikey/apikeyCreate.go @@ -2,7 +2,6 @@ package apikey import ( "encoding/json" - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -37,7 +36,7 @@ func (a *APIKey) Create() (string, string, error) { body, statusCode, err := client.Post(data) if err != nil { if statusCode == 409 { - return "", "", errors.New("API key with this name already exists") + return "", "", fmt.Errorf("API key with this name already exists: %s", err) } return "", "", err diff --git a/pkg/apikey/apikeyDelete.go b/pkg/apikey/apikeyDelete.go index 3d01a18..1e154b1 100644 --- a/pkg/apikey/apikeyDelete.go +++ b/pkg/apikey/apikeyDelete.go @@ -1,7 +1,6 @@ package apikey import ( - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -20,7 +19,7 @@ func (a *APIKey) Delete() (string, int, error) { body, statusCode, err := client.Delete() if err != nil { if statusCode == 404 { - return "", consts.ExitNotFound, errors.New("API key not found") + return "", consts.ExitNotFound, fmt.Errorf("API key not found: %s", err) } return "", consts.ExitError, err diff --git a/pkg/apikey/apikeyList.go b/pkg/apikey/apikeyList.go index bd4437d..b95ca9a 100644 --- a/pkg/apikey/apikeyList.go +++ b/pkg/apikey/apikeyList.go @@ -2,7 +2,6 @@ package apikey import ( "encoding/json" - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -36,9 +35,9 @@ func (a *APIKey) List() (*[]ListItem, string, int, error) { body, statusCode, err := client.Get() if err != nil { if a.Name == "" && statusCode == 404 { - return nil, "", consts.ExitError, errors.New("Org Slug not found") + return nil, "", consts.ExitError, fmt.Errorf("Org Slug not found: %s", err) } else if a.Name != "" && statusCode == 404 { - return nil, "", consts.ExitNotFound, errors.New("key not found") + return nil, "", consts.ExitNotFound, fmt.Errorf("key not found: %s", err) } return nil, "", consts.ExitError, err diff --git a/pkg/grafana/apikey/apikeyCreate.go b/pkg/grafana/apikey/apikeyCreate.go index 71b83ba..393ce68 100644 --- a/pkg/grafana/apikey/apikeyCreate.go +++ b/pkg/grafana/apikey/apikeyCreate.go @@ -2,7 +2,6 @@ package apikey import ( "encoding/json" - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -61,7 +60,7 @@ func (a *APIKey) Create() (string, string, error) { body, statusCode, err := client.Post(data) if err != nil { if statusCode == 409 { - return "", "", errors.New("API key with this name already exists") + return "", "", fmt.Errorf("API key with this name already exists: %s", err) } return "", "", err diff --git a/pkg/grafana/apikey/apikeyDelete.go b/pkg/grafana/apikey/apikeyDelete.go index 4ad4ab2..443728c 100644 --- a/pkg/grafana/apikey/apikeyDelete.go +++ b/pkg/grafana/apikey/apikeyDelete.go @@ -45,7 +45,7 @@ func (a *APIKey) Delete() (string, int, error) { } if keyID == -1 { - return "", consts.ExitNotFound, errors.New("API key not found") + return "", consts.ExitNotFound, errors.New("API key not found in the list of API keys") } client.Endpoint = fmt.Sprintf(a.GrafanaEndpoint+"/%d", keyID) @@ -53,7 +53,7 @@ func (a *APIKey) Delete() (string, int, error) { body, statusCode, err := client.Delete() if err != nil { if statusCode == 404 { - return "", consts.ExitNotFound, errors.New("API key not found") + return "", consts.ExitNotFound, fmt.Errorf("API key not found: %s", err) } return "", consts.ExitError, err diff --git a/pkg/grafana/apikey/apikeyList.go b/pkg/grafana/apikey/apikeyList.go index bef2781..67ac201 100644 --- a/pkg/grafana/apikey/apikeyList.go +++ b/pkg/grafana/apikey/apikeyList.go @@ -2,7 +2,6 @@ package apikey import ( "encoding/json" - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -45,7 +44,7 @@ func (a *APIKey) List() (*ListResp, string, error) { body, statusCode, err := client.Get() if err != nil { if statusCode == 404 { - return nil, "", errors.New("Grafana instance not found") + return nil, "", fmt.Errorf("Grafana instance not found: %s", err) } return nil, "", err diff --git a/pkg/grafana/grafanaRestart.go b/pkg/grafana/grafanaRestart.go index 89fa68f..4694e75 100644 --- a/pkg/grafana/grafanaRestart.go +++ b/pkg/grafana/grafanaRestart.go @@ -1,7 +1,6 @@ package grafana import ( - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -19,7 +18,7 @@ func (g *Grafana) Restart() (string, error) { body, statusCode, err := client.Post(nil) if err != nil { if statusCode == 404 { - return "", errors.New("Stack Slug not found") + return "", fmt.Errorf("Stack Slug not found: %s", err) } return "", err diff --git a/pkg/stack/stackCreate.go b/pkg/stack/stackCreate.go index ad7255b..be0b629 100644 --- a/pkg/stack/stackCreate.go +++ b/pkg/stack/stackCreate.go @@ -2,7 +2,6 @@ package stack import ( "encoding/json" - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -32,7 +31,7 @@ func (s *Stack) Create() (*ListItem, string, error) { body, statusCode, err := client.Post(data) if err != nil { if statusCode == 409 { - return nil, "", errors.New("stack with this name already exists") + return nil, "", fmt.Errorf("stack with this name already exists: %s", err) } return nil, "", err diff --git a/pkg/stack/stackDelete.go b/pkg/stack/stackDelete.go index 72b16bb..e23199c 100644 --- a/pkg/stack/stackDelete.go +++ b/pkg/stack/stackDelete.go @@ -1,7 +1,6 @@ package stack import ( - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -20,7 +19,7 @@ func (s *Stack) Delete() (string, int, error) { body, statusCode, err := client.Delete() if err != nil { if statusCode == 404 { - return "", consts.ExitNotFound, errors.New("API key not found") + return "", consts.ExitNotFound, fmt.Errorf("API key not found: %s", err) } return "", consts.ExitError, err diff --git a/pkg/stack/stackList.go b/pkg/stack/stackList.go index 4f97642..9408230 100644 --- a/pkg/stack/stackList.go +++ b/pkg/stack/stackList.go @@ -2,7 +2,6 @@ package stack import ( "encoding/json" - "errors" "fmt" _client "github.com/jtyr/gcapi/pkg/client" @@ -46,9 +45,9 @@ func (s *Stack) List() (*[]ListItem, string, int, error) { body, statusCode, err := client.Get() if err != nil { if s.StackSlug == "" && statusCode == 404 { - return nil, "", consts.ExitError, errors.New("Org Slug not found") + return nil, "", consts.ExitError, fmt.Errorf("Org Slug not found: %s", err) } else if s.StackSlug != "" && statusCode == 404 { - return nil, "", consts.ExitNotFound, errors.New("Stack not found") + return nil, "", consts.ExitNotFound, fmt.Errorf("Stack not found: %s", err) } return nil, "", consts.ExitError, err