From d1875bb6d86619bf1647fb6d832d78c31c8239ae Mon Sep 17 00:00:00 2001 From: cpanato Date: Wed, 17 Aug 2022 14:32:47 +0200 Subject: [PATCH] use errors.new Signed-off-by: cpanato --- pkg/chart/chart.go | 9 +++++---- pkg/config/config.go | 11 ++++++----- pkg/tool/helm.go | 2 +- pkg/tool/kubectl.go | 5 +++-- pkg/util/util.go | 3 ++- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 90b73d4c..2c63f98f 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -15,6 +15,7 @@ package chart import ( + "errors" "fmt" "os" "path/filepath" @@ -696,7 +697,7 @@ func (t *Testing) FindChartDirsToBeProcessed() ([]string, error) { func (t *Testing) computeMergeBase() (string, error) { err := t.git.ValidateRepository() if err != nil { - return "", fmt.Errorf("must be in a git repository") + return "", errors.New("must be in a git repository") } return t.git.MergeBase(fmt.Sprintf("%s/%s", t.config.Remote, t.config.TargetBranch), t.config.Since) } @@ -791,7 +792,7 @@ func (t *Testing) CheckVersionIncrement(chart *Chart) error { } if result >= 0 { - return fmt.Errorf("chart version not ok. needs a version bump! ") + return errors.New("chart version not ok. Needs a version bump! ") } fmt.Println("Chart version ok.") @@ -845,13 +846,13 @@ func (t *Testing) ValidateMaintainers(chart *Chart) error { if chartYaml.Deprecated { if len(chartYaml.Maintainers) > 0 { - return fmt.Errorf("deprecated chart must not have maintainers") + return errors.New("deprecated chart must not have maintainers") } return nil } if len(chartYaml.Maintainers) == 0 { - return fmt.Errorf("chart doesn't have maintainers") + return errors.New("chart doesn't have maintainers") } repoURL, err := t.git.GetURLForRemote(t.config.Remote) diff --git a/pkg/config/config.go b/pkg/config/config.go index 1241c7f2..1c849c8f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -15,6 +15,7 @@ package config import ( + "errors" "fmt" "os" "path/filepath" @@ -121,18 +122,18 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C } if cfg.ProcessAllCharts && len(cfg.Charts) > 0 { - return nil, fmt.Errorf("specifying both, '--all' and '--charts', is not allowed") + return nil, errors.New("specifying both, '--all' and '--charts', is not allowed") } if cfg.Namespace != "" && cfg.ReleaseLabel == "" { - return nil, fmt.Errorf("specifying '--namespace' without '--release-label' is not allowed") + return nil, errors.New("specifying '--namespace' without '--release-label' is not allowed") } // Disable upgrade (this does some expensive dependency building on previous revisions) // when neither "install" nor "lint-and-install" have not been specified. cfg.Upgrade = isInstall && cfg.Upgrade if (cfg.TargetBranch == "" || cfg.Remote == "") && cfg.Upgrade { - return nil, fmt.Errorf("specifying '--upgrade=true' without '--target-branch' or '--remote', is not allowed") + return nil, errors.New("specifying '--upgrade=true' without '--target-branch' or '--remote', is not allowed") } chartYamlSchemaPath := cfg.ChartYamlSchema @@ -140,7 +141,7 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C var err error cfgFile, err = findConfigFile("chart_schema.yaml") if err != nil && isLint && cfg.ValidateChartSchema { - return nil, fmt.Errorf("'chart_schema.yaml' neither specified nor found in default locations") + return nil, errors.New("'chart_schema.yaml' neither specified nor found in default locations") } cfg.ChartYamlSchema = cfgFile } @@ -150,7 +151,7 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C var err error cfgFile, err = findConfigFile("lintconf.yaml") if err != nil && isLint && cfg.ValidateYaml { - return nil, fmt.Errorf("'lintconf.yaml' neither specified nor found in default locations") + return nil, errors.New("'lintconf.yaml' neither specified nor found in default locations") } cfg.LintConf = cfgFile } diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index 44afd470..f7715d64 100644 --- a/pkg/tool/helm.go +++ b/pkg/tool/helm.go @@ -83,7 +83,7 @@ func (h Helm) Test(namespace string, release string) error { } func (h Helm) DeleteRelease(namespace string, release string) { - fmt.Printf("Deleting release '%s'...\n", release) + fmt.Printf("Deleting release %q...\n", release) if err := h.exec.RunProcess("helm", "uninstall", release, "--namespace", namespace, h.extraArgs); err != nil { fmt.Println("Error deleting Helm release:", err) } diff --git a/pkg/tool/kubectl.go b/pkg/tool/kubectl.go index f3c02df8..5ad72f09 100644 --- a/pkg/tool/kubectl.go +++ b/pkg/tool/kubectl.go @@ -3,6 +3,7 @@ package tool import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" "strings" @@ -106,9 +107,9 @@ func (k Kubectl) forceNamespaceDeletion(namespace string) error { client := retryablehttp.NewClient() client.Logger = nil if resp, err := client.Do(req); err != nil { - return fmt.Errorf(errMsg) + return fmt.Errorf("%s:%w", errMsg, err) } else if resp.StatusCode != http.StatusOK { - return fmt.Errorf(errMsg) + return errors.New(errMsg) } return nil diff --git a/pkg/util/util.go b/pkg/util/util.go index e097d6e3..d3f1974b 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -15,6 +15,7 @@ package util import ( + "errors" "fmt" "io" "io/fs" @@ -154,7 +155,7 @@ func (u Utils) LookupChartDir(chartDirs []string, dir string) (string, error) { } } } - return "", fmt.Errorf("no chart directory") + return "", errors.New("no chart directory") } // ReadChartYaml attempts to parse Chart.yaml within the specified directory