Documentation
¶
Overview ¶
errors with stacktrace.
Index ¶
- Constants
- Variables
- func As[T error](err error) (T, bool)
- func ErrorStackTrace(err error) string
- func IsAny(curr error, others ...error) bool
- func IsNoneErr(err error) bool
- func IsType[T error](err error) bool
- func UnknownErr(err error) error
- func UnknownErrMsgf(msg string, args ...any) error
- func UnknownErrf(err error, msg string, args ...any) error
- func UnwrapErrStack(err error) (string, bool)
- func Wrap(err error) error
- func WrapErrMulti(errs ...error) error
- func WrapErrfCode(err error, code string, msg string, args ...any) error
- func Wrapf(err error, msg string, args ...any) error
- type MisoErr
- func (e *MisoErr) Cause() error
- func (e *MisoErr) Code() string
- func (e *MisoErr) Error() string
- func (e *MisoErr) HasCode() bool
- func (e *MisoErr) InternalMsg() string
- func (e *MisoErr) Is(target error) bool
- func (e *MisoErr) Msg() string
- func (e *MisoErr) New() error
- func (e *MisoErr) StackTrace() string
- func (e *MisoErr) Unwrap() error
- func (e *MisoErr) WithCode(code string) *MisoErr
- func (e *MisoErr) WithInternalMsg(msg string, args ...any) *MisoErr
- func (e *MisoErr) WithMsg(msg string) *MisoErr
- func (e *MisoErr) Wrap(cause error) error
- func (e *MisoErr) Wrapf(cause error, internalMsg string, args ...any) error
Constants ¶
const ( ErrCodeNone string = "MISO_NONE" ErrCodeRecordNotFound string = "RECORD_NOT_FOUND" )
Variables ¶
var (
Errf = NewErrf
)
Functions ¶
func ErrorStackTrace ¶
func UnknownErr ¶
Wrap an error to create new *MisoErr without any extra context.
This is almost equivalent to ErrUnknownError.Wrap(err)
If err is nil, nil is returned.
func UnknownErrMsgf ¶
Equivalent to ErrUnknownError.WithInternalMsg(msg, args...).
func UnwrapErrStack ¶
func Wrap ¶
Wrap an error to create new *MisoErr with stacktrace.
If err is nil, nil is returned.
If err is *MisoErr, err is returned directly.
func WrapErrMulti ¶
Wrap multi errors to create new *MisoErr with stacktrace.
If err is nil, nil is returned.
If err is *MisoErr, err is returned directly.
func WrapErrfCode ¶
Wrap an error to create new MisoErr with message.
If the wrapped err is nil, nil is returned.
Types ¶
type MisoErr ¶
type MisoErr struct {
// contains filtered or unexported fields
}
Miso Error.
Use NewErrf(...) to instantiate.
var ( ErrUnknownError *MisoErr = NewErrfCode(ErrCodeUnknownError, "Unknown Error") ErrNotPermitted *MisoErr = NewErrfCode(ErrCodeNotPermitted, "Not Permitted") ErrIllegalArgument *MisoErr = NewErrfCode(ErrCodeIllegalArgument, "Illegal Argument") ErrServerShuttingDown *MisoErr = NewErrfCode(ErrCodeServerShuttingDown, "Server Shutting Down") ErrRecordNotFound *MisoErr = NewErrfCode(ErrCodeRecordNotFound, "Record Not Found") )
var ( // Error that represents None or Nil. // // Use miso.IsNoneErr(err) to check if an error represents None. NoneErr *MisoErr = NewErrfCode("none", ErrCodeNone) )
func NewErrfCode ¶
Create new *MisoErr with message and error code.
func (*MisoErr) InternalMsg ¶
func (*MisoErr) Is ¶
Implements *MisoErr Is check.
Returns true, if both are *MisoErr and the code matches.
WithInternalMsg always create new error, so we can basically reuse the same error created using 'errs.NewErrf(...).WithCode(...)'
var ErrIllegalArgument = errs.NewErrf(...).WithCode(...) var e1 = ErrIllegalArgument.WithInternalMsg(...) var e2 = ErrIllegalArgument.WithInternalMsg(...) errors.Is(e1, ErrIllegalArgument) errors.Is(e2, ErrIllegalArgument)