🌱 Add counting of shell parsing errors (#1026)

* Add counting of shell parsing errors

* Use existing CheckErrors metric instead

Co-authored-by: Azeem Shaikh <azeemshaikh38@gmail.com>
This commit is contained in:
Chris McGehee 2021-09-22 07:46:29 -07:00 committed by GitHub
parent 44dd10d465
commit 90332a9cb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -24,7 +24,6 @@ var (
errInternalInvalidYamlFile = errors.New("invalid yaml file")
errInternalFilenameMatch = errors.New("filename match error")
errInternalEmptyFile = errors.New("empty file")
errInternalInvalidShellCode = errors.New("invalid shell code")
errInternalCommitishNil = errors.New("commitish is nil")
errInternalBranchNotFound = errors.New("branch not found")
errInvalidGitHubWorkflow = errors.New("invalid GitHub workflow")

View File

@ -682,8 +682,7 @@ func validateShellFileAndRecord(pathfn string, content []byte, files map[string]
// Note: this is caught by internal caller and only printed
// to avoid failing on shell scripts that our parser does not understand.
// Example: https://github.com/openssl/openssl/blob/master/util/shlib_wrap.sh.in
//nolint
return false, sce.CreateInternal(errInternalInvalidShellCode, err.Error())
return false, sce.WithMessage(sce.ErrorShellParsing, err.Error())
}
printer := syntax.NewPrinter()
@ -826,7 +825,7 @@ func isMatchingShellScriptFile(pathfn string, content []byte, shellsToMatch []st
func validateShellFile(pathfn string, content []byte, dl checker.DetailLogger) (bool, error) {
files := make(map[string]bool)
r, err := validateShellFileAndRecord(pathfn, content, files, dl)
if err != nil && errors.Is(err, errInternalInvalidShellCode) {
if err != nil && errors.Is(err, sce.ErrorShellParsing) {
// Discard and print this particular error for now.
dl.Debug(err.Error())
}

View File

@ -27,6 +27,8 @@ var (
ErrorUnsupportedHost = errors.New("unsupported host")
// ErrorInvalidURL indicates the repo's full URL was not passed.
ErrorInvalidURL = errors.New("invalid repo flag")
// ErrorShellParsing indicates there was an error when parsing shell code.
ErrorShellParsing = errors.New("error parsing shell code")
)
// WithMessage wraps any of the errors listed above.
@ -47,6 +49,8 @@ func GetName(err error) string {
return "ErrScorecardInternal"
case errors.Is(err, ErrRepoUnreachable):
return "ErrRepoUnreachable"
case errors.Is(err, ErrorShellParsing):
return "ErrorShellParsing"
default:
return "ErrUnknown"
}