mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 08:55:27 +03:00
🌱 enable style linter errname
(#3587)
* enable errname linter Signed-off-by: Spencer Schrock <sschrock@google.com> * convert publish err to custom error type. Signed-off-by: Spencer Schrock <sschrock@google.com> * remove unused exported error. Signed-off-by: Spencer Schrock <sschrock@google.com> * convert unsupported exporter type to custom error type. Signed-off-by: Spencer Schrock <sschrock@google.com> * exempt public errors from linter. Signed-off-by: Spencer Schrock <sschrock@google.com> * exempt cron config errors from linter. Signed-off-by: Spencer Schrock <sschrock@google.com> --------- Signed-off-by: Spencer Schrock <sschrock@google.com>
This commit is contained in:
parent
1c649cb66d
commit
5eca374b1e
@ -26,6 +26,7 @@ linters:
|
||||
- asciicheck
|
||||
- dogsled
|
||||
- errcheck
|
||||
- errname
|
||||
- errorlint
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
|
@ -59,12 +59,15 @@ const (
|
||||
)
|
||||
|
||||
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")
|
||||
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")
|
||||
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)
|
||||
ErrorNoConfig = errors.New("no configuration file provided with --" + configFlag) //nolint:errname
|
||||
//go:embed config.yaml
|
||||
configYAML []byte
|
||||
configFilename = flag.String(configFlag, configDefault, configUsage)
|
||||
|
@ -17,7 +17,6 @@ package pubsub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
@ -31,7 +30,13 @@ import (
|
||||
"github.com/ossf/scorecard/v4/cron/data"
|
||||
)
|
||||
|
||||
var errorPublish = errors.New("total errors when publishing")
|
||||
type publishError struct {
|
||||
count uint64
|
||||
}
|
||||
|
||||
func (pe publishError) Error() string {
|
||||
return fmt.Sprintf("total errors when publishing: %d", pe.count)
|
||||
}
|
||||
|
||||
// Publisher interface is used to publish cron job requests to PubSub.
|
||||
type Publisher interface {
|
||||
@ -88,7 +93,7 @@ func (publisher *publisherImpl) Publish(request *data.ScorecardBatchRequest) err
|
||||
func (publisher *publisherImpl) Close() error {
|
||||
publisher.wg.Wait()
|
||||
if publisher.totalErrors > 0 {
|
||||
return fmt.Errorf("%w: %d", errorPublish, publisher.totalErrors)
|
||||
return publishError{count: publisher.totalErrors}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package pubsub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@ -25,9 +24,6 @@ import (
|
||||
"github.com/ossf/scorecard/v4/cron/data"
|
||||
)
|
||||
|
||||
// ErrorInParse indicates there was an error while unmarshalling the protocol buffer message.
|
||||
var ErrorInParse = errors.New("error during protojson.Unmarshal")
|
||||
|
||||
// Subscriber interface is used pull messages from PubSub.
|
||||
type Subscriber interface {
|
||||
SynchronousPull() (*data.ScorecardBatchRequest, error)
|
||||
@ -49,7 +45,7 @@ func CreateSubscriber(ctx context.Context, subscriptionURL string) (Subscriber,
|
||||
func parseJSONToRequest(jsonData []byte) (*data.ScorecardBatchRequest, error) {
|
||||
ret := &data.ScorecardBatchRequest{}
|
||||
if err := protojson.Unmarshal(jsonData, ret); err != nil {
|
||||
return nil, fmt.Errorf("%w: %v", ErrorInParse, err)
|
||||
return nil, fmt.Errorf("protojson.Unmarshal: %w", err)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@ -27,7 +26,13 @@ import (
|
||||
"github.com/ossf/scorecard/v4/cron/config"
|
||||
)
|
||||
|
||||
var errorUndefinedExporter = errors.New("unsupported exporterType")
|
||||
type unsupportedExporterError struct {
|
||||
exporter string
|
||||
}
|
||||
|
||||
func (u unsupportedExporterError) Error() string {
|
||||
return "unsupported exporterType: " + u.exporter
|
||||
}
|
||||
|
||||
type exporterType string
|
||||
|
||||
@ -59,7 +64,7 @@ func GetExporter() (Exporter, error) {
|
||||
case printer:
|
||||
return new(printerExporter), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %s", errorUndefinedExporter, exporter)
|
||||
return nil, unsupportedExporterError{exporter: exporter}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,20 +20,23 @@ import (
|
||||
)
|
||||
|
||||
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.
|
||||
|
||||
// ErrScorecardInternal indicates a runtime error in Scorecard code.
|
||||
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")
|
||||
ErrorUnsupportedHost = errors.New("unsupported host") //nolint:errname
|
||||
// ErrorInvalidURL indicates the repo's full URL was not passed.
|
||||
ErrorInvalidURL = errors.New("invalid repo flag")
|
||||
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")
|
||||
ErrorShellParsing = errors.New("error parsing shell code") //nolint:errname
|
||||
// ErrorUnsupportedCheck indicates check cannot be run for given request.
|
||||
ErrorUnsupportedCheck = errors.New("check is not supported for this 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")
|
||||
ErrorCheckRuntime = errors.New("check runtime error") //nolint:errname
|
||||
)
|
||||
|
||||
// WithMessage wraps any of the errors listed above.
|
||||
|
Loading…
Reference in New Issue
Block a user