Skip to content

Commit 39e968d

Browse files
authoredApr 18, 2024··
⚠️ errors in ErrXXX format (#4040)
Signed-off-by: Case Wylie <[email protected]>
1 parent 0b9dfb6 commit 39e968d

File tree

12 files changed

+44
-44
lines changed

12 files changed

+44
-44
lines changed
 

‎checker/check_runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (r *Runner) Run(ctx context.Context, c Check) CheckResult {
9292
unsupported := ListUnsupported(r.CheckRequest.RequiredTypes, c.SupportedRequestTypes)
9393
if len(unsupported) != 0 {
9494
return CreateRuntimeErrorResult(r.CheckName,
95-
sce.WithMessage(sce.ErrorUnsupportedCheck,
95+
sce.WithMessage(sce.ErrUnsupportedCheck,
9696
fmt.Sprintf("requiredType: %s not supported by check %s", fmt.Sprint(unsupported), r.CheckName)))
9797
}
9898

‎checks/raw/shell_download_validate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ func validateShellFileAndRecord(pathfn string, startLine, endLine uint, content
10971097
if errors.As(err, &parseError) {
10981098
content := string(content)
10991099
r.ProcessingErrors = append(r.ProcessingErrors, checker.ElementError{
1100-
Err: sce.WithMessage(sce.ErrorShellParsing, parseError.Text),
1100+
Err: sce.WithMessage(sce.ErrShellParsing, parseError.Text),
11011101
Location: finding.Location{
11021102
Path: pathfn,
11031103
LineStart: &startLine,
@@ -1108,7 +1108,7 @@ func validateShellFileAndRecord(pathfn string, startLine, endLine uint, content
11081108
})
11091109
return nil
11101110
}
1111-
return sce.WithMessage(sce.ErrorShellParsing, err.Error())
1111+
return sce.WithMessage(sce.ErrShellParsing, err.Error())
11121112
}
11131113

11141114
printer := syntax.NewPrinter()

‎checks/webhook.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func WebHooks(c *checker.CheckRequest) checker.CheckResult {
4747
Text: "SCORECARD_EXPERIMENTAL is not set, not running the Webhook check",
4848
})
4949

50-
e := sce.WithMessage(sce.ErrorUnsupportedCheck, "SCORECARD_EXPERIMENTAL is not set, not running the Webhook check")
50+
e := sce.WithMessage(sce.ErrUnsupportedCheck, "SCORECARD_EXPERIMENTAL is not set, not running the Webhook check")
5151
return checker.CreateRuntimeErrorResult(CheckWebHooks, e)
5252
}
5353

‎clients/githubrepo/repo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (r *repoURL) parse(input string) error {
6565
const splitLen = 2
6666
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen)
6767
if len(split) != splitLen {
68-
return sce.WithMessage(sce.ErrorInvalidURL, fmt.Sprintf("%v. Expected full repository url", input))
68+
return sce.WithMessage(sce.ErrInvalidURL, fmt.Sprintf("%v. Expected full repository url", input))
6969
}
7070

7171
r.host, r.owner, r.repo = u.Host, split[0], split[1]
@@ -93,11 +93,11 @@ func (r *repoURL) IsValid() error {
9393
case "github.com":
9494
case githubHost:
9595
default:
96-
return sce.WithMessage(sce.ErrorUnsupportedHost, r.host)
96+
return sce.WithMessage(sce.ErrUnsupportedHost, r.host)
9797
}
9898

9999
if strings.TrimSpace(r.owner) == "" || strings.TrimSpace(r.repo) == "" {
100-
return sce.WithMessage(sce.ErrorInvalidURL,
100+
return sce.WithMessage(sce.ErrInvalidURL,
101101
fmt.Sprintf("%v. Expected the full repository url", r.URI()))
102102
}
103103
return nil

‎clients/gitlabrepo/repo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (r *repoURL) parse(input string) error {
8888
const splitLen = 2
8989
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen)
9090
if len(split) != splitLen {
91-
return sce.WithMessage(sce.ErrorInvalidURL, fmt.Sprintf("%v. Expected full repository url", input))
91+
return sce.WithMessage(sce.ErrInvalidURL, fmt.Sprintf("%v. Expected full repository url", input))
9292
}
9393

9494
r.scheme, r.host, r.owner, r.project = u.Scheme, u.Host, split[0], split[1]
@@ -120,7 +120,7 @@ func (r *repoURL) String() string {
120120
// IsValid implements Repo.IsValid.
121121
func (r *repoURL) IsValid() error {
122122
if strings.TrimSpace(r.owner) == "" || strings.TrimSpace(r.project) == "" {
123-
return sce.WithMessage(sce.ErrorInvalidURL, "expected full project url: "+r.URI())
123+
return sce.WithMessage(sce.ErrInvalidURL, "expected full project url: "+r.URI())
124124
}
125125

126126
if strings.Contains(r.host, "gitlab.") {

‎cmd/internal/scdiff/app/runner/runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (r *Runner) Run(repoURI string) (pkg.ScorecardResult, error) {
7272
r.log("processing repo: " + repoURI)
7373
repoClient := r.githubClient
7474
repo, err := githubrepo.MakeGithubRepo(repoURI)
75-
if errors.Is(err, sce.ErrorUnsupportedHost) {
75+
if errors.Is(err, sce.ErrUnsupportedHost) {
7676
repo, err = gitlabrepo.MakeGitlabRepo(repoURI)
7777
repoClient = r.gitlabClient
7878
}

‎cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func rootCmd(o *options.Options) error {
175175
// intentionally placed at end to preserve outputting results, even if a check has a runtime error
176176
for _, result := range repoResult.Checks {
177177
if result.Error != nil {
178-
return sce.WithMessage(sce.ErrorCheckRuntime, fmt.Sprintf("%s: %v", result.Name, result.Error))
178+
return sce.WithMessage(sce.ErrCheckRuntime, fmt.Sprintf("%s: %v", result.Name, result.Error))
179179
}
180180
}
181181
return nil

‎cron/config/config.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ var (
6262
// some of these errors didn't follow naming conventions when they were introduced.
6363
// for backward compatibility reasons, they can't be changed and have nolint directives.
6464

65-
// ErrorEmptyConfigValue indicates the value for the configuration option was empty.
66-
ErrorEmptyConfigValue = errors.New("config value set to empty") //nolint:errname
67-
// ErrorValueConversion indicates an unexpected type was found for the value of the config option.
68-
ErrorValueConversion = errors.New("unexpected type, cannot convert value") //nolint:errname
69-
// ErrorNoConfig indicates no config file was provided, or flag.Parse() was not called.
70-
ErrorNoConfig = errors.New("no configuration file provided with --" + configFlag) //nolint:errname
65+
// ErrEmptyConfigValue indicates the value for the configuration option was empty.
66+
ErrEmptyConfigValue = errors.New("config value set to empty")
67+
// ErrValueConversion indicates an unexpected type was found for the value of the config option.
68+
ErrValueConversion = errors.New("unexpected type, cannot convert value")
69+
// ErrNoConfig indicates no config file was provided, or flag.Parse() was not called.
70+
ErrNoConfig = errors.New("no configuration file provided with --" + configFlag)
7171
//go:embed config.yaml
7272
configYAML []byte
7373
configFilename = flag.String(configFlag, configDefault, configUsage)
@@ -121,12 +121,12 @@ func getStringConfigValue(envVar string, byteValue []byte, fieldName, configName
121121
return "", fmt.Errorf("error getting config value %s: %w", configName, err)
122122
}
123123
if value.Kind() != reflect.String {
124-
return "", fmt.Errorf("%w: %s, %s", ErrorValueConversion, value.Type().Name(), configName)
124+
return "", fmt.Errorf("%w: %s, %s", ErrValueConversion, value.Type().Name(), configName)
125125
}
126126
if value.String() != "" {
127127
return value.String(), nil
128128
}
129-
return value.String(), fmt.Errorf("%w: %s", ErrorEmptyConfigValue, configName)
129+
return value.String(), fmt.Errorf("%w: %s", ErrEmptyConfigValue, configName)
130130
}
131131

132132
func getIntConfigValue(envVar string, byteValue []byte, fieldName, configName string) (int, error) {
@@ -142,7 +142,7 @@ func getIntConfigValue(envVar string, byteValue []byte, fieldName, configName st
142142
case reflect.Int:
143143
return int(value.Int()), nil
144144
default:
145-
return 0, fmt.Errorf("%w: %s, %s", ErrorValueConversion, value.Type().Name(), configName)
145+
return 0, fmt.Errorf("%w: %s, %s", ErrValueConversion, value.Type().Name(), configName)
146146
}
147147
}
148148

@@ -159,7 +159,7 @@ func getFloat64ConfigValue(envVar string, byteValue []byte, fieldName, configNam
159159
case reflect.Float32, reflect.Float64:
160160
return value.Float(), nil
161161
default:
162-
return 0, fmt.Errorf("%w: %s, %s", ErrorValueConversion, value.Type().Name(), configName)
162+
return 0, fmt.Errorf("%w: %s, %s", ErrValueConversion, value.Type().Name(), configName)
163163
}
164164
}
165165

@@ -183,11 +183,11 @@ func getMapConfigValue(byteValue []byte, fieldName, configName, subMapName strin
183183
return map[string]string{}, fmt.Errorf("error getting config value %s: %w", configName, err)
184184
}
185185
if value.Kind() != reflect.Map {
186-
return map[string]string{}, fmt.Errorf("%w: %s, %s", ErrorValueConversion, value.Type().Name(), configName)
186+
return map[string]string{}, fmt.Errorf("%w: %s, %s", ErrValueConversion, value.Type().Name(), configName)
187187
}
188188
subMap := value.MapIndex(reflect.ValueOf(subMapName))
189189
if subMap.Kind() != reflect.Map {
190-
return map[string]string{}, fmt.Errorf("%w: %s, %s", ErrorValueConversion, value.Type().Name(), configName)
190+
return map[string]string{}, fmt.Errorf("%w: %s, %s", ErrValueConversion, value.Type().Name(), configName)
191191
}
192192
ret := map[string]string{}
193193
iter := subMap.MapRange()
@@ -277,7 +277,7 @@ func GetShardSize() (int, error) {
277277
// GetWebhookURL returns the webhook URL to ping on a successful cron job completion.
278278
func GetWebhookURL() (string, error) {
279279
url, err := getStringConfigValue(webhookURL, configYAML, "WebhookURL", "webhook-url")
280-
if err != nil && !errors.Is(err, ErrorEmptyConfigValue) {
280+
if err != nil && !errors.Is(err, ErrEmptyConfigValue) {
281281
return url, err
282282
}
283283
return url, nil
@@ -327,7 +327,7 @@ func GetInputBucketPrefix() (string, error) {
327327
if err != nil {
328328
// TODO temporarily falling back to old variables until changes propagate to production
329329
prefix, err := getStringConfigValue(inputBucketPrefix, configYAML, "InputBucketPrefix", "input-bucket-prefix")
330-
if err != nil && !errors.Is(err, ErrorEmptyConfigValue) {
330+
if err != nil && !errors.Is(err, ErrEmptyConfigValue) {
331331
return "", err
332332
}
333333
return prefix, nil

‎cron/config/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestGetStringConfigValue(t *testing.T) {
194194
envVal: "",
195195
setEnv: true,
196196
hasError: true,
197-
expectedErr: ErrorEmptyConfigValue,
197+
expectedErr: ErrEmptyConfigValue,
198198
},
199199
}
200200
for _, testcase := range testcases {

‎cron/data/iterator_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ func TestCsvIterator(t *testing.T) {
152152
outcomes: []outcome{
153153
{
154154
hasError: true,
155-
expectedErr: sce.ErrorInvalidURL,
155+
expectedErr: sce.ErrInvalidURL,
156156
},
157157
{
158158
hasError: true,
159-
expectedErr: sce.ErrorInvalidURL,
159+
expectedErr: sce.ErrInvalidURL,
160160
},
161161
{
162162
hasError: true,
163-
expectedErr: sce.ErrorInvalidURL,
163+
expectedErr: sce.ErrInvalidURL,
164164
},
165165
},
166166
},

‎errors/public.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ var (
2727
ErrScorecardInternal = errors.New("internal error")
2828
// ErrRepoUnreachable indicates Scorecard is unable to establish connection with the repository.
2929
ErrRepoUnreachable = errors.New("repo unreachable")
30-
// ErrorUnsupportedHost indicates the repo's host is unsupported.
31-
ErrorUnsupportedHost = errors.New("unsupported host") //nolint:errname
32-
// ErrorInvalidURL indicates the repo's full URL was not passed.
33-
ErrorInvalidURL = errors.New("invalid repo flag") //nolint:errname
34-
// ErrorShellParsing indicates there was an error when parsing shell code.
35-
ErrorShellParsing = errors.New("error parsing shell code") //nolint:errname
30+
// ErrUnsupportedHost indicates the repo's host is unsupported.
31+
ErrUnsupportedHost = errors.New("unsupported host")
32+
// ErrInvalidURL indicates the repo's full URL was not passed.
33+
ErrInvalidURL = errors.New("invalid repo flag")
34+
// ErrShellParsing indicates there was an error when parsing shell code.
35+
ErrShellParsing = errors.New("error parsing shell code")
3636
// ErrJobOSParsing indicates there was an error when detecting a job's operating system.
3737
ErrJobOSParsing = errors.New("error parsing job operating system")
38-
// ErrorUnsupportedCheck indicates check cannot be run for given request.
39-
ErrorUnsupportedCheck = errors.New("check is not supported for this request") //nolint:errname
40-
// ErrorCheckRuntime indicates an individual check had a runtime error.
41-
ErrorCheckRuntime = errors.New("check runtime error") //nolint:errname
38+
// ErrUnsupportedCheck indicates check cannot be run for given request.
39+
ErrUnsupportedCheck = errors.New("check is not supported for this request")
40+
// ErrCheckRuntime indicates an individual check had a runtime error.
41+
ErrCheckRuntime = errors.New("check runtime error")
4242
)
4343

4444
// WithMessage wraps any of the errors listed above.
@@ -59,8 +59,8 @@ func GetName(err error) string {
5959
return "ErrScorecardInternal"
6060
case errors.Is(err, ErrRepoUnreachable):
6161
return "ErrRepoUnreachable"
62-
case errors.Is(err, ErrorShellParsing):
63-
return "ErrorShellParsing"
62+
case errors.Is(err, ErrShellParsing):
63+
return "ErrShellParsing"
6464
default:
6565
return "ErrUnknown"
6666
}

‎errors/public_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ func TestGetName(t *testing.T) {
8383
want: "ErrRepoUnreachable",
8484
},
8585
{
86-
name: "ErrorShellParsing",
86+
name: "ErrShellParsing",
8787
args: args{
88-
err: ErrorShellParsing,
88+
err: ErrShellParsing,
8989
},
90-
want: "ErrorShellParsing",
90+
want: "ErrShellParsing",
9191
},
9292
{
9393
name: "unknown error",

0 commit comments

Comments
 (0)
Please sign in to comment.