Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit a290a87

Browse files
ferhatelmasdlorenc
authored andcommitted
util: simplify error creation (#163)
- use `fmt.Errorf` instead of `errors.New(fmt.Sprintf())`
1 parent 335d37c commit a290a87

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

util/analyze_output_utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (r ListAnalyzeResult) OutputText(resultType string) error {
4545
analysis, valid := r.Analysis.([]string)
4646
if !valid {
4747
logrus.Error("Unexpected structure of Analysis. Should be of type []string")
48-
return errors.New(fmt.Sprintf("Could not output %s analysis result", r.AnalyzeType))
48+
return fmt.Errorf("Could not output %s analysis result", r.AnalyzeType)
4949
}
5050
r.Analysis = analysis
5151

@@ -58,7 +58,7 @@ func (r MultiVersionPackageAnalyzeResult) OutputStruct() interface{} {
5858
analysis, valid := r.Analysis.(map[string]map[string]PackageInfo)
5959
if !valid {
6060
logrus.Error("Unexpected structure of Analysis. Should be of type map[string]map[string]PackageInfo")
61-
return errors.New(fmt.Sprintf("Could not output %s analysis result", r.AnalyzeType))
61+
return fmt.Errorf("Could not output %s analysis result", r.AnalyzeType)
6262
}
6363
analysisOutput := getMultiVersionPackageOutput(analysis)
6464
output := struct {
@@ -77,7 +77,7 @@ func (r MultiVersionPackageAnalyzeResult) OutputText(resultType string) error {
7777
analysis, valid := r.Analysis.(map[string]map[string]PackageInfo)
7878
if !valid {
7979
logrus.Error("Unexpected structure of Analysis. Should be of type map[string]map[string]PackageInfo")
80-
return errors.New(fmt.Sprintf("Could not output %s analysis result", r.AnalyzeType))
80+
return fmt.Errorf("Could not output %s analysis result", r.AnalyzeType)
8181
}
8282
analysisOutput := getMultiVersionPackageOutput(analysis)
8383

@@ -100,7 +100,7 @@ func (r SingleVersionPackageAnalyzeResult) OutputStruct() interface{} {
100100
analysis, valid := r.Analysis.(map[string]PackageInfo)
101101
if !valid {
102102
logrus.Error("Unexpected structure of Analysis. Should be of type map[string]PackageInfo")
103-
return errors.New(fmt.Sprintf("Could not output %s analysis result", r.AnalyzeType))
103+
return fmt.Errorf("Could not output %s analysis result", r.AnalyzeType)
104104
}
105105
analysisOutput := getSingleVersionPackageOutput(analysis)
106106
output := struct {
@@ -119,7 +119,7 @@ func (r SingleVersionPackageAnalyzeResult) OutputText(diffType string) error {
119119
analysis, valid := r.Analysis.(map[string]PackageInfo)
120120
if !valid {
121121
logrus.Error("Unexpected structure of Analysis. Should be of type map[string]PackageInfo")
122-
return errors.New(fmt.Sprintf("Could not output %s analysis result", r.AnalyzeType))
122+
return fmt.Errorf("Could not output %s analysis result", r.AnalyzeType)
123123
}
124124
analysisOutput := getSingleVersionPackageOutput(analysis)
125125

util/diff_output_utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (r MultiVersionPackageDiffResult) OutputStruct() interface{} {
3636
diff, valid := r.Diff.(MultiVersionPackageDiff)
3737
if !valid {
3838
logrus.Error("Unexpected structure of Diff. Should follow the MultiVersionPackageDiff struct")
39-
return errors.New(fmt.Sprintf("Could not output %s diff result", r.DiffType))
39+
return fmt.Errorf("Could not output %s diff result", r.DiffType)
4040
}
4141

4242
diffOutput := struct {
@@ -56,7 +56,7 @@ func (r MultiVersionPackageDiffResult) OutputText(diffType string) error {
5656
diff, valid := r.Diff.(MultiVersionPackageDiff)
5757
if !valid {
5858
logrus.Error("Unexpected structure of Diff. Should follow the MultiVersionPackageDiff struct")
59-
return errors.New(fmt.Sprintf("Could not output %s diff result", r.DiffType))
59+
return fmt.Errorf("Could not output %s diff result", r.DiffType)
6060
}
6161

6262
strPackages1 := stringifyPackages(getMultiVersionPackageOutput(diff.Packages1))
@@ -102,7 +102,7 @@ func (r SingleVersionPackageDiffResult) OutputStruct() interface{} {
102102
diff, valid := r.Diff.(PackageDiff)
103103
if !valid {
104104
logrus.Error("Unexpected structure of Diff. Should follow the PackageDiff struct")
105-
return errors.New(fmt.Sprintf("Could not output %s diff result", r.DiffType))
105+
return fmt.Errorf("Could not output %s diff result", r.DiffType)
106106
}
107107

108108
diffOutput := struct {
@@ -122,7 +122,7 @@ func (r SingleVersionPackageDiffResult) OutputText(diffType string) error {
122122
diff, valid := r.Diff.(PackageDiff)
123123
if !valid {
124124
logrus.Error("Unexpected structure of Diff. Should follow the PackageDiff struct")
125-
return errors.New(fmt.Sprintf("Could not output %s diff result", r.DiffType))
125+
return fmt.Errorf("Could not output %s diff result", r.DiffType)
126126
}
127127

128128
strPackages1 := stringifyPackages(getSingleVersionPackageOutput(diff.Packages1))

0 commit comments

Comments
 (0)