Skip to content

Commit

Permalink
add errorlint linter
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Jun 24, 2024
1 parent f6a5aa2 commit 1c622b2
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 22 deletions.
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))

Check warning on line 535 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L535

Added line #L535 was not covered by tests
return NoCompression
}

Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlplog/otlploggrpc/internal/retry/retry.go
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
2 changes: 1 addition & 1 deletion exporters/otlp/otlplog/otlploghttp/internal/retry/retry.go
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)

Check warning on line 82 in exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go#L82

Added line #L82 was not covered by tests
}
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)

Check warning on line 82 in exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go#L82

Added line #L82 was not covered by tests
}
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) {
// 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)

Check warning on line 89 in exporters/zipkin/zipkin.go

View check run for this annotation

Codecov / codecov/patch

exporters/zipkin/zipkin.go#L89

Added line #L89 was not covered by tests
}
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

0 comments on commit 1c622b2

Please sign in to comment.