Skip to content

Commit

Permalink
use errors.new
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Sep 16, 2022
1 parent be7ab88 commit d1875bb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
9 changes: 5 additions & 4 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package chart

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package config

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -121,26 +122,26 @@ 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
if chartYamlSchemaPath == "" {
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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tool/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/tool/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tool
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package util

import (
"errors"
"fmt"
"io"
"io/fs"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d1875bb

Please sign in to comment.