You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +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:
		| @@ -11,6 +11,7 @@ linters: | ||||
|   enable: | ||||
|     - depguard | ||||
|     - errcheck | ||||
|     - errorlint | ||||
|     - godot | ||||
|     - gofumpt | ||||
|     - goimports | ||||
|   | ||||
| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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 | ||||
| 	} | ||||
|   | ||||
| @@ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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...) | ||||
|   | ||||
| @@ -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 | ||||
| 	} | ||||
|   | ||||
| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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...) | ||||
|   | ||||
| @@ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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 | ||||
| 	} | ||||
|   | ||||
| @@ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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 | ||||
| 			} | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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...) | ||||
|   | ||||
| @@ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -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 | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user