@@ -11,26 +11,26 @@ import (
11
11
"go.opentelemetry.io/collector/consumer/consumererror/internal/statusconversion"
12
12
)
13
13
14
- // Error acts as a container for errors coming from pipeline components.
14
+ // ErrorContainer acts as a container for errors coming from pipeline components.
15
15
// It may hold multiple errors from downstream components, and is designed
16
16
// to act as a way to accumulate errors as it travels upstream in a pipeline.
17
- // `Error ` should be obtained using `errors.As` and as a result, ideally
17
+ // `ErrorContainer ` should be obtained using `errors.As` and as a result, ideally
18
18
// a single instance should exist in an error stack. If this is not possible,
19
- // the most `Error ` object should be highest on the stack.
19
+ // the most `ErrorContainer ` object should be highest on the stack.
20
20
//
21
21
// Experimental: This API is at the early stage of development and may change without backward compatibility
22
- type Error struct {
23
- errors []ErrorData
22
+ type ErrorContainer struct {
23
+ errors []Error
24
24
}
25
25
26
- // ErrorData is intended to be used to encapsulate various information
26
+ // Error is intended to be used to encapsulate various information
27
27
// that can add context to an error that occurred within a pipeline component.
28
- // ErrorData objects are constructed through calling `New` with the relevant
28
+ // Error objects are constructed through calling `New` with the relevant
29
29
// options to capture data around the error that occurred. It can then be pulled
30
30
// out by an upstream component by calling `Error.Data`.
31
31
//
32
32
// Experimental: This API is at the early stage of development and may change without backward compatibility
33
- type ErrorData interface {
33
+ type Error interface {
34
34
Error () string
35
35
36
36
Unwrap () error
@@ -55,32 +55,40 @@ type errorData struct {
55
55
}
56
56
57
57
// ErrorOption allows annotating an Error with metadata.
58
- type ErrorOption func (error * errorData )
58
+ type ErrorOption interface {
59
+ applyOption (* errorData )
60
+ }
61
+
62
+ type errorOptionFunc func (* errorData )
63
+
64
+ func (f errorOptionFunc ) applyOption (e * errorData ) {
65
+ f (e )
66
+ }
59
67
60
68
// New wraps an error that happened while consuming telemetry
61
69
// and adds metadata onto it to be passed back up the pipeline.
62
70
//
63
71
// Experimental: This API is at the early stage of development and may change without backward compatibility
64
72
func New (origErr error , options ... ErrorOption ) error {
65
73
errData := & errorData {error : origErr }
66
- err := & Error {errors : []ErrorData {errData }}
74
+ err := & ErrorContainer {errors : []Error {errData }}
67
75
68
76
for _ , option := range options {
69
- option (errData )
77
+ option . applyOption (errData )
70
78
}
71
79
72
80
return err
73
81
}
74
82
75
- var _ error = & Error {}
83
+ var _ error = ( * ErrorContainer )( nil )
76
84
77
85
// Error implements the `error` interface.
78
- func (e * Error ) Error () string {
86
+ func (e * ErrorContainer ) Error () string {
79
87
return e .errors [len (e .errors )- 1 ].Error ()
80
88
}
81
89
82
90
// Unwrap returns the wrapped error for use by `errors.Is` and `errors.As`.
83
- func (e * Error ) Unwrap () []error {
91
+ func (e * ErrorContainer ) Unwrap () []error {
84
92
errors := make ([]error , 0 , len (e .errors ))
85
93
86
94
for _ , err := range e .errors {
@@ -90,21 +98,21 @@ func (e *Error) Unwrap() []error {
90
98
return errors
91
99
}
92
100
93
- // Data returns all the accumulated ErrorData errors
101
+ // Errors returns all the accumulated Error objects
94
102
// emitted by components downstream in the pipeline.
95
103
// These can then be aggregated or worked with individually.
96
- func (e * Error ) Data () []ErrorData {
104
+ func (e * ErrorContainer ) Errors () []Error {
97
105
return e .errors
98
106
}
99
107
100
108
// Combine joins errors that occur at a fanout into a single
101
109
// `Error` object. The component that created the data submission
102
110
// can then work with the `Error` object to understand the failure.
103
- func Combine (errs ... error ) * Error {
104
- e := & Error {errors : make ([]ErrorData , 0 , len (errs ))}
111
+ func Combine (errs ... error ) * ErrorContainer {
112
+ e := & ErrorContainer {errors : make ([]Error , 0 , len (errs ))}
105
113
106
114
for _ , err := range errs {
107
- var otherErr * Error
115
+ var otherErr * ErrorContainer
108
116
if errors .As (err , & otherErr ) {
109
117
e .errors = append (e .errors , otherErr .errors ... )
110
118
} else {
@@ -118,17 +126,17 @@ func Combine(errs ...error) *Error {
118
126
// WithHTTPStatus records an HTTP status code that was received
119
127
// from a server during data submission.
120
128
func WithHTTPStatus (status int ) ErrorOption {
121
- return func (err * errorData ) {
129
+ return errorOptionFunc ( func (err * errorData ) {
122
130
err .httpStatus = & status
123
- }
131
+ })
124
132
}
125
133
126
134
// WithGRPCStatus records a gRPC status code that was received
127
135
// from a server during data submission.
128
136
func WithGRPCStatus (status * status.Status ) ErrorOption {
129
- return func (err * errorData ) {
137
+ return errorOptionFunc ( func (err * errorData ) {
130
138
err .grpcStatus = status
131
- }
139
+ })
132
140
}
133
141
134
142
var _ error = (* errorData )(nil )
0 commit comments