mirror of
https://github.com/ossf/scorecard.git
synced 2024-10-03 20:32:27 +03:00
⚠️ errors in ErrXXX format (#4040)
Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
This commit is contained in:
parent
0b9dfb656f
commit
39e968dceb
@ -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)))
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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]
|
||||
@ -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
|
||||
|
@ -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]
|
||||
@ -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.") {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
@ -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) {
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -194,7 +194,7 @@ func TestGetStringConfigValue(t *testing.T) {
|
||||
envVal: "",
|
||||
setEnv: true,
|
||||
hasError: true,
|
||||
expectedErr: ErrorEmptyConfigValue,
|
||||
expectedErr: ErrEmptyConfigValue,
|
||||
},
|
||||
}
|
||||
for _, testcase := range testcases {
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -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.
|
||||
@ -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"
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user