Documentation
¶
Index ¶
- type Err
- func (e *Err) AddContext(key string, value any)
- func (e *Err) AddFrame(prefix, call string)
- func (e *Err) AddSuggestion(suggestion string)
- func (e *Err) ChangeSeverity(new_severity SeverityLevel)
- func (e Err) Error() string
- func (e *Err) SetInner(inner error)
- func (e Err) Value(key string) (any, bool)
- type ErrorCoder
- type SeverityLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Err ¶
type Err struct {
// Code is the error code.
Code ErrorCoder
// Message is the error message.
Message string
// Suggestions is a list of suggestions for the user.
Suggestions []string
// Severity is the severity level of the error.
Severity SeverityLevel
// Timestamp is the timestamp of the error.
Timestamp time.Time
// Context is the context of the error.
Context map[string]any
// StackTrace is the stack trace of the error.
StackTrace *internal.StackTrace
// Inner is the inner error of the error.
Inner error
}
Err represents a generalized error.
func New ¶
func New[C ErrorCoder](code C, message string) *Err
New creates a new error.
Parameters:
- code: The error code.
- message: The error message.
Returns:
- *Err: A pointer to the new error. Never returns nil.
func NewWithSeverity ¶
func NewWithSeverity[C ErrorCoder](severity SeverityLevel, code C, message string) *Err
NewWithSeverity creates a new error.
Parameters:
- severity: The severity level of the error.
- code: The error code.
- message: The error message.
Returns:
- *Err: A pointer to the new error. Never returns nil.
func (*Err) AddContext ¶
AddContext adds a context to the error. Does nothing if the receiver is nil.
Parameters:
- key: The key of the context.
- value: The value of the context.
func (*Err) AddFrame ¶
AddFrame prepends a frame to the stack trace. Does nothing if the receiver is nil or the trace is empty.
Parameters:
- prefix: The prefix of the frame.
- call: The call of the frame.
If prefix is empty, the call is used as the frame. Otherwise a dot is added between the prefix and the call.
func (*Err) AddSuggestion ¶
AddSuggestion adds a suggestion to the error. Does nothing if the receiver is nil.
Parameters:
- suggestion: The suggestion to add.
func (*Err) ChangeSeverity ¶
func (e *Err) ChangeSeverity(new_severity SeverityLevel)
ChangeSeverity changes the severity level of the error. Does nothing if the receiver is nil.
Parameters:
- new_severity: The new severity level of the error.
type ErrorCoder ¶
type ErrorCoder interface {
// Int returns the integer value of the error code.
//
// Returns:
// - int: The integer value of the error code.
Int() int
fmt.Stringer
}
ErrorCoder is an interface that all error codes must implement.
type SeverityLevel ¶
type SeverityLevel int
SeverityLevel represents the severity level of an error.
const ( // INFO is the severity level for informational messages. // (i.e., errors that are not critical nor fatal) // // Mostly used for message passing. INFO SeverityLevel = iota // WARNING is the severity level for warning messages. // (i.e., errors that are not critical nor fatal, yet worthy of attention). WARNING // ERROR is the severity level for error messages. // (i.e., the standard error level). ERROR // FATAL is the severity level for fatal errors. // (i.e., the highest severity level). // // These are usually panic-level of errors. FATAL )
func (SeverityLevel) String ¶
func (i SeverityLevel) String() string