Documentation
¶
Index ¶
- func HasCode(err error, code ErrorCode) bool
- func RootCause(err error) error
- type Error
- func (e *Error) As(target interface{}) bool
- func (e *Error) AsRetryable() *Error
- func (e *Error) Error() string
- func (e *Error) ErrorCode() ErrorCode
- func (e *Error) Is(target error) bool
- func (e *Error) IsRetryable() bool
- func (e *Error) MarshalJSON() ([]byte, error)
- func (e *Error) Unwrap() error
- func (e *Error) UserMessage() string
- func (e *Error) WithContext(key string, value interface{}) *Error
- func (e *Error) WithSeverity(severity string) *Error
- func (e *Error) WithUserMessage(msg string) *Error
- type ErrorCode
- type ErrorCoder
- type Retryable
- type Stacktrace
- type UserMessager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Field string `json:"field,omitempty"`
Value string `json:"value,omitempty"`
Context map[string]interface{} `json:"context,omitempty"`
Timestamp time.Time `json:"timestamp"`
Cause error `json:"cause,omitempty"`
Severity string `json:"severity"`
Stack *Stacktrace `json:"stack,omitempty"`
UserMsg string `json:"user_msg,omitempty"`
Retryable bool `json:"retryable,omitempty"`
}
Error represents a structured error with context and cause
func NewWithContext ¶
NewWithContext creates a new error with additional context
func NewWithField ¶
NewWithField creates a new error with field and value
func (*Error) As ¶
As implements errors.As compatibility. It delegates the check to the underlying Cause. Note: It will not match the *Error instance itself, only errors in its cause chain.
func (*Error) AsRetryable ¶ added in v1.0.2
AsRetryable marks the error as retryable.
func (*Error) IsRetryable ¶
IsRetryable returns whether the error is retryable.
func (*Error) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for Error.
func (*Error) UserMessage ¶
UserMessage returns the user-friendly message if set, otherwise the technical message.
func (*Error) WithContext ¶ added in v1.0.2
WithContext adds or updates context information on the error.
func (*Error) WithSeverity ¶ added in v1.0.2
WithSeverity sets the severity level of the error.
func (*Error) WithUserMessage ¶
WithUserMessage sets a user-friendly message on the error.
type ErrorCoder ¶
type ErrorCoder interface {
ErrorCode() ErrorCode
}
ErrorCoder allows extracting a code from an error.
type Retryable ¶
type Retryable interface {
IsRetryable() bool
}
Retryable marks an error as retryable.
type Stacktrace ¶
type Stacktrace struct {
Frames []uintptr
}
Stacktrace holds a slice of program counters for error tracing.
func CaptureStacktrace ¶
func CaptureStacktrace(skip int) *Stacktrace
CaptureStacktrace returns a new Stacktrace from the current call stack.
func (*Stacktrace) String ¶
func (s *Stacktrace) String() string
String returns a human-readable stacktrace.
type UserMessager ¶
type UserMessager interface {
UserMessage() string
}
UserMessager allows extracting a user-friendly message from an error.