Debian Codegraph @

exporters/stdout/stdoutlog/internal/partialsuccess.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package internal // import "go.opentelemetry.io/otel/exporters/stdout/stdoutlog/internal"
5
6 import "fmt"
7
8 // PartialSuccess represents the underlying error for all handling
9 // stdoutlog partial success messages. Use `errors.Is(err, PartialSuccess{})`
10 // to test whether an error passed to the stdoutlog error handler belongs to this category.
11 type PartialSuccess struct {
12 ErrorMessage string
13 RejectedItems int64
14 RejectedKind string
15 }
16
17 var _ error = PartialSuccess{}
18
19 // Error implements the error interface.
20 func (ps PartialSuccess) Error() string {
21 msg := ps.ErrorMessage
22 if msg == "" {
23 msg = "empty message"
24 }
25 return fmt.Sprintf("stdoutlog partial success: %s (%d %s failed)", msg, ps.RejectedItems, ps.RejectedKind)
26 }
27
28 // Is supports the errors.Is() interface.
29 func (PartialSuccess) Is(err error) bool {
30 _, ok := err.(PartialSuccess)
31 return ok
32 }
33
34 // LogPartialSuccessError returns an error describing a partial success
35 // response for the log signal.
36 func LogPartialSuccessError(itemsRejected int64, errorMessage string) error {
37 return PartialSuccess{
38 ErrorMessage: errorMessage,
39 RejectedItems: itemsRejected,
40 RejectedKind: "logs",
41 }
42 }