Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ errors in ErrXXX format #4040

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checker/check_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *Runner) Run(ctx context.Context, c Check) CheckResult {
unsupported := ListUnsupported(r.CheckRequest.RequiredTypes, c.SupportedRequestTypes)
if len(unsupported) != 0 {
return CreateRuntimeErrorResult(r.CheckName,
sce.WithMessage(sce.ErrorUnsupportedCheck,
sce.WithMessage(sce.ErrUnsupportedCheck,
fmt.Sprintf("requiredType: %s not supported by check %s", fmt.Sprint(unsupported), r.CheckName)))
}

Expand Down
4 changes: 2 additions & 2 deletions checks/raw/shell_download_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ func validateShellFileAndRecord(pathfn string, startLine, endLine uint, content
if errors.As(err, &parseError) {
content := string(content)
r.ProcessingErrors = append(r.ProcessingErrors, checker.ElementError{
Err: sce.WithMessage(sce.ErrorShellParsing, parseError.Text),
Err: sce.WithMessage(sce.ErrShellParsing, parseError.Text),
Location: finding.Location{
Path: pathfn,
LineStart: &startLine,
Expand All @@ -1108,7 +1108,7 @@ func validateShellFileAndRecord(pathfn string, startLine, endLine uint, content
})
return nil
}
return sce.WithMessage(sce.ErrorShellParsing, err.Error())
return sce.WithMessage(sce.ErrShellParsing, err.Error())
}

printer := syntax.NewPrinter()
Expand Down
2 changes: 1 addition & 1 deletion checks/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func WebHooks(c *checker.CheckRequest) checker.CheckResult {
Text: "SCORECARD_EXPERIMENTAL is not set, not running the Webhook check",
})

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

Expand Down
6 changes: 3 additions & 3 deletions clients/githubrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r *repoURL) parse(input string) error {
const splitLen = 2
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen)
if len(split) != splitLen {
return sce.WithMessage(sce.ErrorInvalidURL, fmt.Sprintf("%v. Expected full repository url", input))
return sce.WithMessage(sce.ErrInvalidURL, fmt.Sprintf("%v. Expected full repository url", input))
}

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

if strings.TrimSpace(r.owner) == "" || strings.TrimSpace(r.repo) == "" {
return sce.WithMessage(sce.ErrorInvalidURL,
return sce.WithMessage(sce.ErrInvalidURL,
fmt.Sprintf("%v. Expected the full repository url", r.URI()))
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions clients/gitlabrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r *repoURL) parse(input string) error {
const splitLen = 2
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen)
if len(split) != splitLen {
return sce.WithMessage(sce.ErrorInvalidURL, fmt.Sprintf("%v. Expected full repository url", input))
return sce.WithMessage(sce.ErrInvalidURL, fmt.Sprintf("%v. Expected full repository url", input))
}

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

if strings.Contains(r.host, "gitlab.") {
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/scdiff/app/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r *Runner) Run(repoURI string) (pkg.ScorecardResult, error) {
r.log("processing repo: " + repoURI)
repoClient := r.githubClient
repo, err := githubrepo.MakeGithubRepo(repoURI)
if errors.Is(err, sce.ErrorUnsupportedHost) {
if errors.Is(err, sce.ErrUnsupportedHost) {
repo, err = gitlabrepo.MakeGitlabRepo(repoURI)
repoClient = r.gitlabClient
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func rootCmd(o *options.Options) error {
// intentionally placed at end to preserve outputting results, even if a check has a runtime error
for _, result := range repoResult.Checks {
if result.Error != nil {
return sce.WithMessage(sce.ErrorCheckRuntime, fmt.Sprintf("%s: %v", result.Name, result.Error))
return sce.WithMessage(sce.ErrCheckRuntime, fmt.Sprintf("%s: %v", result.Name, result.Error))
}
}
return nil
Expand Down
28 changes: 14 additions & 14 deletions cron/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ var (
// some of these errors didn't follow naming conventions when they were introduced.
// for backward compatibility reasons, they can't be changed and have nolint directives.

// ErrorEmptyConfigValue indicates the value for the configuration option was empty.
ErrorEmptyConfigValue = errors.New("config value set to empty") //nolint:errname
// ErrorValueConversion indicates an unexpected type was found for the value of the config option.
ErrorValueConversion = errors.New("unexpected type, cannot convert value") //nolint:errname
// ErrorNoConfig indicates no config file was provided, or flag.Parse() was not called.
ErrorNoConfig = errors.New("no configuration file provided with --" + configFlag) //nolint:errname
// ErrEmptyConfigValue indicates the value for the configuration option was empty.
ErrEmptyConfigValue = errors.New("config value set to empty")
// ErrValueConversion indicates an unexpected type was found for the value of the config option.
ErrValueConversion = errors.New("unexpected type, cannot convert value")
// ErrNoConfig indicates no config file was provided, or flag.Parse() was not called.
ErrNoConfig = errors.New("no configuration file provided with --" + configFlag)
//go:embed config.yaml
configYAML []byte
configFilename = flag.String(configFlag, configDefault, configUsage)
Expand Down Expand Up @@ -121,12 +121,12 @@ func getStringConfigValue(envVar string, byteValue []byte, fieldName, configName
return "", fmt.Errorf("error getting config value %s: %w", configName, err)
}
if value.Kind() != reflect.String {
return "", fmt.Errorf("%w: %s, %s", ErrorValueConversion, value.Type().Name(), configName)
return "", fmt.Errorf("%w: %s, %s", ErrValueConversion, value.Type().Name(), configName)
}
if value.String() != "" {
return value.String(), nil
}
return value.String(), fmt.Errorf("%w: %s", ErrorEmptyConfigValue, configName)
return value.String(), fmt.Errorf("%w: %s", ErrEmptyConfigValue, configName)
}

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

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

Expand All @@ -183,11 +183,11 @@ func getMapConfigValue(byteValue []byte, fieldName, configName, subMapName strin
return map[string]string{}, fmt.Errorf("error getting config value %s: %w", configName, err)
}
if value.Kind() != reflect.Map {
return map[string]string{}, fmt.Errorf("%w: %s, %s", ErrorValueConversion, value.Type().Name(), configName)
return map[string]string{}, fmt.Errorf("%w: %s, %s", ErrValueConversion, value.Type().Name(), configName)
}
subMap := value.MapIndex(reflect.ValueOf(subMapName))
if subMap.Kind() != reflect.Map {
return map[string]string{}, fmt.Errorf("%w: %s, %s", ErrorValueConversion, value.Type().Name(), configName)
return map[string]string{}, fmt.Errorf("%w: %s, %s", ErrValueConversion, value.Type().Name(), configName)
}
ret := map[string]string{}
iter := subMap.MapRange()
Expand Down Expand Up @@ -277,7 +277,7 @@ func GetShardSize() (int, error) {
// GetWebhookURL returns the webhook URL to ping on a successful cron job completion.
func GetWebhookURL() (string, error) {
url, err := getStringConfigValue(webhookURL, configYAML, "WebhookURL", "webhook-url")
if err != nil && !errors.Is(err, ErrorEmptyConfigValue) {
if err != nil && !errors.Is(err, ErrEmptyConfigValue) {
return url, err
}
return url, nil
Expand Down Expand Up @@ -327,7 +327,7 @@ func GetInputBucketPrefix() (string, error) {
if err != nil {
// TODO temporarily falling back to old variables until changes propagate to production
prefix, err := getStringConfigValue(inputBucketPrefix, configYAML, "InputBucketPrefix", "input-bucket-prefix")
if err != nil && !errors.Is(err, ErrorEmptyConfigValue) {
if err != nil && !errors.Is(err, ErrEmptyConfigValue) {
return "", err
}
return prefix, nil
Expand Down
2 changes: 1 addition & 1 deletion cron/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestGetStringConfigValue(t *testing.T) {
envVal: "",
setEnv: true,
hasError: true,
expectedErr: ErrorEmptyConfigValue,
expectedErr: ErrEmptyConfigValue,
},
}
for _, testcase := range testcases {
Expand Down
6 changes: 3 additions & 3 deletions cron/data/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ func TestCsvIterator(t *testing.T) {
outcomes: []outcome{
{
hasError: true,
expectedErr: sce.ErrorInvalidURL,
expectedErr: sce.ErrInvalidURL,
},
{
hasError: true,
expectedErr: sce.ErrorInvalidURL,
expectedErr: sce.ErrInvalidURL,
},
{
hasError: true,
expectedErr: sce.ErrorInvalidURL,
expectedErr: sce.ErrInvalidURL,
},
},
},
Expand Down
24 changes: 12 additions & 12 deletions errors/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ var (
ErrScorecardInternal = errors.New("internal error")
// ErrRepoUnreachable indicates Scorecard is unable to establish connection with the repository.
ErrRepoUnreachable = errors.New("repo unreachable")
// ErrorUnsupportedHost indicates the repo's host is unsupported.
ErrorUnsupportedHost = errors.New("unsupported host") //nolint:errname
// ErrorInvalidURL indicates the repo's full URL was not passed.
ErrorInvalidURL = errors.New("invalid repo flag") //nolint:errname
// ErrorShellParsing indicates there was an error when parsing shell code.
ErrorShellParsing = errors.New("error parsing shell code") //nolint:errname
// ErrUnsupportedHost indicates the repo's host is unsupported.
ErrUnsupportedHost = errors.New("unsupported host")
// ErrInvalidURL indicates the repo's full URL was not passed.
ErrInvalidURL = errors.New("invalid repo flag")
// ErrShellParsing indicates there was an error when parsing shell code.
ErrShellParsing = errors.New("error parsing shell code")
// ErrJobOSParsing indicates there was an error when detecting a job's operating system.
ErrJobOSParsing = errors.New("error parsing job operating system")
// ErrorUnsupportedCheck indicates check cannot be run for given request.
ErrorUnsupportedCheck = errors.New("check is not supported for this request") //nolint:errname
// ErrorCheckRuntime indicates an individual check had a runtime error.
ErrorCheckRuntime = errors.New("check runtime error") //nolint:errname
// ErrUnsupportedCheck indicates check cannot be run for given request.
ErrUnsupportedCheck = errors.New("check is not supported for this request")
// ErrCheckRuntime indicates an individual check had a runtime error.
ErrCheckRuntime = errors.New("check runtime error")
)

// WithMessage wraps any of the errors listed above.
Expand All @@ -59,8 +59,8 @@ func GetName(err error) string {
return "ErrScorecardInternal"
case errors.Is(err, ErrRepoUnreachable):
return "ErrRepoUnreachable"
case errors.Is(err, ErrorShellParsing):
return "ErrorShellParsing"
case errors.Is(err, ErrShellParsing):
return "ErrShellParsing"
default:
return "ErrUnknown"
}
Expand Down
6 changes: 3 additions & 3 deletions errors/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func TestGetName(t *testing.T) {
want: "ErrRepoUnreachable",
},
{
name: "ErrorShellParsing",
name: "ErrShellParsing",
args: args{
err: ErrorShellParsing,
err: ErrShellParsing,
},
want: "ErrorShellParsing",
want: "ErrShellParsing",
},
{
name: "unknown error",
Expand Down
Loading