-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
57 lines (47 loc) · 2.05 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package xsqs
import (
"errors"
"fmt"
)
var _, _ error = new(BulkError), new(BulkMessageError)
type (
// BulkError represents an error that occurs during bulk message processing.
// It contains a list of BulkMessageError instances that provide detailed information about individual message errors.
// This error is intended for use with BulkConsumer.
BulkError struct {
Errors []BulkMessageError // List of individual message errors.
}
// BulkMessageError represents an error that occurs while processing an individual message in a bulk operation.
// It contains the MessageID of the message and the corresponding error.
BulkMessageError struct {
MessageID string
Err error
}
)
// unrecoverableError is a wrapper error type indicating that an error is unrecoverable.
// This type is used for errors that signal that the processing of a message is not recoverable and should not be retried.
type unrecoverableError struct{ error }
// UnrecoverableError creates a new unrecoverable error.
// Unrecoverable errors indicate that the processing of a message is not recoverable and should not be retried.
func UnrecoverableError(err error) error {
return &unrecoverableError{err}
}
// IsUnrecoverableError checks if an error is an unrecoverable error.
// It returns true if the error is an unrecoverable error created using the UnrecoverableError function.
func IsUnrecoverableError(err error) bool {
var unrecovable *unrecoverableError
return errors.As(err, &unrecovable)
}
// Error returns the string representation of a BulkError.
func (e BulkError) Error() string {
return fmt.Sprintf("bulk messages processing error, %d messages were unprocessed", len(e.Errors))
}
// Error returns the string representation of a BulkMessageError.
func (e BulkMessageError) Error() string {
return fmt.Sprintf("message %s was not been processed: %s", e.MessageID, e.Err.Error())
}
// Unwrap returns the underlying error of a BulkMessageError.
// It allows accessing the original error that caused the BulkMessageError.
func (e BulkMessageError) Unwrap() error {
return e.Err
}