| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package consumererror // import "go.opentelemetry.io/collector/consumer/consumererror" |
| 5 |
|
| 6 |
import "errors" |
| 7 |
|
| 8 |
type downstreamError struct { |
| 9 |
inner error |
| 10 |
} |
| 11 |
|
| 12 |
var _ error = downstreamError{} |
| 13 |
|
| 14 |
func (de downstreamError) Error() string { |
| 15 |
return de.inner.Error() |
| 16 |
} |
| 17 |
|
| 18 |
func (de downstreamError) Unwrap() error { |
| 19 |
return de.inner |
| 20 |
} |
| 21 |
|
| 22 |
// NewDownstream wraps an error to indicate that it is a downstream error, i.e. an |
| 23 |
// error that does not come from the current component, but from one further downstream. |
| 24 |
// This is used by pipeline instrumentation to determine whether an operation's outcome |
| 25 |
// was an internal failure, or if it successfully produced data that was later refused. |
| 26 |
// This wrapper is not intended to be used manually inside components. |
| 27 |
func NewDownstream(err error) error { |
| 28 |
return downstreamError{ |
| 29 |
inner: err, |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
// IsDownstream checks if an error was wrapped with the NewDownstream function, |
| 34 |
// or if it contains one such error in its Unwrap() tree. |
| 35 |
func IsDownstream(err error) bool { |
| 36 |
var de downstreamError |
| 37 |
return errors.As(err, &de) |
| 38 |
} |