Documentation ¶
Index ¶
- Constants
- Variables
- type CodeHinter
- type Error
- func (e Error) As(err any) bool
- func (e Error) Code() int
- func (e Error) Context() map[string]any
- func (e Error) Display() string
- func (e Error) Error() string
- func (e Error) Is(err error) bool
- func (e Error) IsNil() bool
- func (e Error) MarshalJSONObject(enc *gojay.Encoder)
- func (e Error) Message() string
- func (e *Error) SetCode(code int) *Error
- func (e *Error) SetContext(values ...any) *Error
- func (e *Error) SetMessage(msg string) *Error
- func (e Error) String() string
- func (e Error) Unwrap() error
- func (e Error) WriteDisplay(s types.StringWriter)
- func (e Error) WriteError(sw io.StringWriter)
- type ErrorWriter
Constants ¶
const NilText = "gasket: nil"
Variables ¶
var Nil = errors.New(NilText)
Functions ¶
This section is empty.
Types ¶
type CodeHinter ¶
type CodeHinter interface { // Gets the type's code. Code() int }
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func HasCode ¶
If somewhere on the error chain, gasket.(*Error) exists, and have the given code, returns that gasket.(*Error), otherwise returns nil.
func Wrap ¶
Wraps error with extra informations.
If error is a type of gasket.Error (more superficially implements types.CodeHinter), it will take the code from the type.
func (Error) MarshalJSONObject ¶
func (*Error) SetCode ¶
Set the code for error (and thus what types.CodeHinter interface will return).
func (*Error) SetContext ¶
Sets the error context.
Values must be alternating between string and other values, with even index as string. If value is not of type string, it will be coerced to string using fmt.Sprintf.
Values must be at least of Length of two, otherwise it will be ignored.
Example:
err.SetContext("key", value, "key2", value2)
func (*Error) SetMessage ¶
Set message for current error.
func (Error) WriteDisplay ¶
func (e Error) WriteDisplay(s types.StringWriter)
Collect accumulated Human Readable output to s. Ignore must not be returned, nor does it should panic, because this is just intended for human read.
Interface implementer will not return how much bytes written or error.
So ensure the Writer is reliable and can consume everything without error, e.g. bytes.Buffer or strings.Builder.
func (Error) WriteError ¶
func (e Error) WriteError(sw io.StringWriter)
type ErrorWriter ¶
type ErrorWriter interface {
WriteError(sw io.StringWriter)
}