Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 421fd14

Browse files
committed
Remove custom error names
In Golang, error names are generally repeated with the same variable rather being given their own unique names. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent e0d3c5f commit 421fd14

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

cmd/apply.go

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ type InstallPreferences struct {
5656
}
5757

5858
func runApplyCommandE(command *cobra.Command, _ []string) error {
59-
6059
prefs := InstallPreferences{}
6160

61+
if os.Getuid() == 0 {
62+
return fmt.Errorf("do not run this tool as root, or on your server. Run it from your own client remotely")
63+
}
64+
6265
files, err := command.Flags().GetStringArray("file")
6366
if err != nil {
6467
return err
@@ -85,49 +88,40 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
8588
return fmt.Errorf("provide one or more --file arguments")
8689
}
8790

88-
if os.Getuid() == 0 {
89-
return fmt.Errorf("do not run this tool as root, or on your server. Run it from your own client remotely")
90-
}
91-
9291
plans := []types.Plan{}
93-
94-
log.Printf("Loading %d plan(s)..OK.\n", len(files))
9592
for _, yamlFile := range files {
9693

97-
yamlBytes, yamlErr := ioutil.ReadFile(yamlFile)
98-
if yamlErr != nil {
99-
return fmt.Errorf("loading --file %s gave error: %s", yamlFile, yamlErr.Error())
94+
yamlBytes, err := ioutil.ReadFile(yamlFile)
95+
if err != nil {
96+
return fmt.Errorf("loading --file %s gave error: %s", yamlFile, err.Error())
10097
}
10198

10299
plan := types.Plan{}
103-
unmarshalErr := yaml.Unmarshal(yamlBytes, &plan)
104-
if unmarshalErr != nil {
105-
return fmt.Errorf("unmarshal of --file %s gave error: %s", yamlFile, unmarshalErr.Error())
100+
if err := yaml.Unmarshal(yamlBytes, &plan);err != nil {
101+
return fmt.Errorf("unmarshal of --file %s gave error: %s", yamlFile, err.Error())
106102
}
103+
107104
log.Printf("%s loaded\n", yamlFile)
108105
plans = append(plans, plan)
109106
}
110107

111-
planMerged, mergeErr := types.MergePlans(plans)
112-
113-
if mergeErr != nil {
114-
return mergeErr
108+
log.Printf("Loaded %d plan(s)\n", len(files))
109+
planMerged, err := types.MergePlans(plans)
110+
if err != nil {
111+
return err
115112
}
116113

117114
if printPlan {
118-
119115
out, _ := yaml.Marshal(planMerged)
120116
fmt.Println(string(out))
121-
122117
os.Exit(0)
123118
}
124119

125120
plan := *planMerged
126121

127-
var featuresErr error
128-
plan, featuresErr = filterFeatures(plan)
129-
if featuresErr != nil {
130-
return fmt.Errorf("error while retreiving features: %s", featuresErr.Error())
122+
plan, err = filterFeatures(plan)
123+
if err != nil {
124+
return fmt.Errorf("error while retreiving features: %s", err.Error())
131125
}
132126

133127
clientArch, clientOS := env.GetClientArch()
@@ -138,8 +132,7 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
138132
fmt.Printf("User dir: %s\n", userDir)
139133

140134
install := []string{"kubectl", "helm", "faas-cli", "arkade", "kubeseal"}
141-
err = getTools(clientArch, clientOS, userDir, install)
142-
if err != nil {
135+
if err := getTools(clientArch, clientOS, userDir, install); err != nil {
143136
return err
144137
}
145138

@@ -171,9 +164,8 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
171164
}
172165

173166
if prefs.SkipCreateSecrets == false {
174-
validateErr := validatePlan(plan)
175-
if validateErr != nil {
176-
panic(validateErr)
167+
if err := validatePlan(plan); err != nil {
168+
return errors.Wrap(err, "validatePlan")
177169
}
178170
}
179171

pkg/types/secrets.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func BuildSecretTask(kvn KeyValueNamespaceTuple) execute.ExecTask {
6363
}
6464

6565
func generateSecret() (string, error) {
66-
6766
pass, err := password.Generate(25, 10, 0, false, true)
6867
if err != nil {
6968
return "", err

0 commit comments

Comments
 (0)