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

Add errorlint linter #5535

Merged
merged 3 commits into from
Jun 25, 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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ linters:
enable:
- depguard
- errcheck
- errorlint
- godot
- gofumpt
- goimports
Expand Down
2 changes: 1 addition & 1 deletion baggage/baggage.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func parseMember(member string) (Member, error) {
// Decode a percent-encoded value.
value, err := url.PathUnescape(val)
if err != nil {
return newInvalidMember(), fmt.Errorf("%w: %v", errInvalidValue, err)
return newInvalidMember(), fmt.Errorf("%w: %w", errInvalidValue, err)
}
return Member{key: key, value: value, properties: props, hasData: true}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlplog/otlploggrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func loadCertificates(certPath, keyPath string) ([]tls.Certificate, error) {
func compressorToCompression(compressor string) Compression {
c, err := convCompression(compressor)
if err != nil {
otel.Handle(fmt.Errorf("%s, using no compression as default", err))
otel.Handle(fmt.Errorf("%w, using no compression as default", err))
return NoCompression
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc {
}

if ctxErr := waitFunc(ctx, delay); ctxErr != nil {
return fmt.Errorf("%w: %s", ctxErr, err)
return fmt.Errorf("%w: %w", ctxErr, err)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion exporters/otlp/otlplog/otlploghttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ func evaluate(err error) (bool, time.Duration) {
return false, 0
}

rErr, ok := err.(retryableError)
// Do not use errors.As here, this should only be flattened one layer. If
// there are several chained errors, all the errors above it will be
// discarded if errors.As is used instead.
rErr, ok := err.(retryableError) //nolint:errorlint
if !ok {
return false, 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc {
}

if ctxErr := waitFunc(ctx, delay); ctxErr != nil {
return fmt.Errorf("%w: %s", ctxErr, err)
return fmt.Errorf("%w: %w", ctxErr, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (e *Exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) e
return fmt.Errorf("failed to upload metrics: %w", upErr)
}
// Merge the two errors.
return fmt.Errorf("failed to upload incomplete metrics (%s): %w", err, upErr)
return fmt.Errorf("failed to upload incomplete metrics (%w): %w", err, upErr)
}
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc {
}

if ctxErr := waitFunc(ctx, delay); ctxErr != nil {
return fmt.Errorf("%w: %s", ctxErr, err)
return fmt.Errorf("%w: %w", ctxErr, err)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (e *multiErr) append(err error) {
// Do not use errors.As here, this should only be flattened one layer. If
// there is a *multiErr several steps down the chain, all the errors above
// it will be discarded if errors.As is used instead.
switch other := err.(type) {
switch other := err.(type) { //nolint:errorlint
case *multiErr:
// Flatten err errors into e.
e.errs = append(e.errs, other.errs...)
Expand Down
5 changes: 4 additions & 1 deletion exporters/otlp/otlpmetric/otlpmetrichttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ func evaluate(err error) (bool, time.Duration) {
return false, 0
}

rErr, ok := err.(retryableError)
// Do not use errors.As here, this should only be flattened one layer. If
// there are several chained errors, all the errors above it will be
// discarded if errors.As is used instead.
rErr, ok := err.(retryableError) //nolint:errorlint
if !ok {
return false, 0
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (e *Exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) e
return fmt.Errorf("failed to upload metrics: %w", upErr)
}
// Merge the two errors.
return fmt.Errorf("failed to upload incomplete metrics (%s): %w", err, upErr)
return fmt.Errorf("failed to upload incomplete metrics (%w): %w", err, upErr)
}
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc {
}

if ctxErr := waitFunc(ctx, delay); ctxErr != nil {
return fmt.Errorf("%w: %s", ctxErr, err)
return fmt.Errorf("%w: %w", ctxErr, err)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (e *multiErr) append(err error) {
// Do not use errors.As here, this should only be flattened one layer. If
// there is a *multiErr several steps down the chain, all the errors above
// it will be discarded if errors.As is used instead.
switch other := err.(type) {
switch other := err.(type) { //nolint:errorlint
case *multiErr:
// Flatten err errors into e.
e.errs = append(e.errs, other.errs...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc {
}

if ctxErr := waitFunc(ctx, delay); ctxErr != nil {
return fmt.Errorf("%w: %s", ctxErr, err)
return fmt.Errorf("%w: %w", ctxErr, err)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion exporters/otlp/otlptrace/otlptracehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ func evaluate(err error) (bool, time.Duration) {
return false, 0
}

rErr, ok := err.(retryableError)
// Do not use errors.As here, this should only be flattened one layer. If
// there are several chained errors, all the errors above it will be
// discarded if errors.As is used instead.
rErr, ok := err.(retryableError) //nolint:errorlint
if !ok {
return false, 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc {
}

if ctxErr := waitFunc(ctx, delay); ctxErr != nil {
return fmt.Errorf("%w: %s", ctxErr, err)
return fmt.Errorf("%w: %w", ctxErr, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {

if !c.disableScopeInfo {
scopeInfo, err := c.scopeInfo(scopeMetrics.Scope)
if err == errScopeInvalid {
if errors.Is(err, errScopeInvalid) {
dmathieu marked this conversation as resolved.
Show resolved Hide resolved
// Do not report the same error multiple times.
continue
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/zipkin/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func New(collectorURL string, opts ...Option) (*Exporter, error) {
}
u, err := url.Parse(collectorURL)
if err != nil {
return nil, fmt.Errorf("invalid collector URL %q: %v", collectorURL, err)
return nil, fmt.Errorf("invalid collector URL %q: %w", collectorURL, err)
}
if u.Scheme == "" || u.Host == "" {
return nil, fmt.Errorf("invalid collector URL %q: no scheme or host", collectorURL)
Expand Down
2 changes: 1 addition & 1 deletion internal/shared/otlp/otlpmetric/transform/error.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (e *multiErr) append(err error) {
// Do not use errors.As here, this should only be flattened one layer. If
// there is a *multiErr several steps down the chain, all the errors above
// it will be discarded if errors.As is used instead.
switch other := err.(type) {
switch other := err.(type) { //nolint:errorlint
case *multiErr:
// Flatten err errors into e.
e.errs = append(e.errs, other.errs...)
Expand Down
2 changes: 1 addition & 1 deletion internal/shared/otlp/retry/retry.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc {
}

if ctxErr := waitFunc(ctx, delay); ctxErr != nil {
return fmt.Errorf("%w: %s", ctxErr, err)
return fmt.Errorf("%w: %w", ctxErr, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/periodic_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (r *PeriodicReader) Shutdown(ctx context.Context) error {
}

sErr := r.exporter.Shutdown(ctx)
if err == nil || err == ErrReaderShutdown {
if err == nil || errors.Is(err, ErrReaderShutdown) {
err = sErr
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/batch_span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestBatchSpanProcessorExportTimeout(t *testing.T) {
generateSpan(t, tr, testOption{genNumSpans: 1})
tp.UnregisterSpanProcessor(bsp)

if exp.err != context.DeadlineExceeded {
if !errors.Is(exp.err, context.DeadlineExceeded) {
t.Errorf("context deadline error not returned: got %+v", exp.err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (p *TracerProvider) Shutdown(ctx context.Context) error {
retErr = err
} else {
// Poor man's list of errors
retErr = fmt.Errorf("%v; %v", retErr, err)
retErr = fmt.Errorf("%w; %w", retErr, err)
}
}
}
Expand Down