1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-26 21:05:00 +02:00

Add errorlint linter (#5535)

This is the last PR adding missing linters, adding
[errorlint](https://github.com/polyfloyd/go-errorlint).

Co-authored-by: Sam Xie <sam@samxie.me>
This commit is contained in:
Damien Mathieu 2024-06-25 19:55:00 +02:00 committed by GitHub
parent 921eb701b1
commit 6d45f283c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 32 additions and 22 deletions

View File

@ -11,6 +11,7 @@ linters:
enable:
- depguard
- errcheck
- errorlint
- godot
- gofumpt
- goimports

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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...)

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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...)

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -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)

View File

@ -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...)

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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)
}
}
}