errs

package
v0.4.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

errors with stacktrace.

Index

Constants

View Source
const (
	ErrCodeNone           string = "MISO_NONE"
	ErrCodeRecordNotFound string = "RECORD_NOT_FOUND"
)
View Source
const (
	ErrCodeGeneric            string = "XXXX"
	ErrCodeUnknownError       string = "UNKNOWN_ERROR"
	ErrCodeNotPermitted       string = "NOT_PERMITTED"
	ErrCodeIllegalArgument    string = "ILLEGAL_ARGUMENT"
	ErrCodeServerShuttingDown string = "SERVER_SHUTTING_DOWN"
)

Variables

View Source
var (
	Errf = NewErrf
)

Functions

func As

func As[T error](err error) (T, bool)

func ErrorStackTrace

func ErrorStackTrace(err error) string

func IsAny

func IsAny(curr error, others ...error) bool

func IsNoneErr

func IsNoneErr(err error) bool

Check if the error represents None

func IsType

func IsType[T error](err error) bool

func UnknownErr

func UnknownErr(err error) error

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

func UnknownErrMsgf(msg string, args ...any) error

Equivalent to ErrUnknownError.WithInternalMsg(msg, args...).

func UnknownErrf

func UnknownErrf(err error, msg string, args ...any) error

Equivalent to ErrUnknownError.Wrapf(..).

If err is nil, nil is returned.

func UnwrapErrStack

func UnwrapErrStack(err error) (string, bool)

func Wrap

func Wrap(err error) error

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

func WrapErrMulti(errs ...error) error

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

func WrapErrfCode(err error, code string, msg string, args ...any) error

Wrap an error to create new MisoErr with message.

If the wrapped err is nil, nil is returned.

func Wrapf

func Wrapf(err error, msg string, args ...any) error

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 NewErrf

func NewErrf(msg string, args ...any) *MisoErr

Create new *MisoErr with message.

func NewErrfCode

func NewErrfCode(code string, msg string, args ...any) *MisoErr

Create new *MisoErr with message and error code.

func (*MisoErr) Cause

func (e *MisoErr) Cause() error

func (*MisoErr) Code

func (e *MisoErr) Code() string

func (*MisoErr) Error

func (e *MisoErr) Error() string

func (*MisoErr) HasCode

func (e *MisoErr) HasCode() bool

func (*MisoErr) InternalMsg

func (e *MisoErr) InternalMsg() string

func (*MisoErr) Is

func (e *MisoErr) Is(target error) bool

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)

func (*MisoErr) Msg

func (e *MisoErr) Msg() string

func (*MisoErr) New

func (e *MisoErr) New() error

func (*MisoErr) StackTrace

func (e *MisoErr) StackTrace() string

func (*MisoErr) Unwrap

func (e *MisoErr) Unwrap() error

func (*MisoErr) WithCode

func (e *MisoErr) WithCode(code string) *MisoErr

func (*MisoErr) WithInternalMsg

func (e *MisoErr) WithInternalMsg(msg string, args ...any) *MisoErr

func (*MisoErr) WithMsg

func (e *MisoErr) WithMsg(msg string) *MisoErr

func (*MisoErr) Wrap

func (e *MisoErr) Wrap(cause error) error

Create new *MisoErr to wrap the cause error

if cause is nil, nil is returned.

func (*MisoErr) Wrapf

func (e *MisoErr) Wrapf(cause error, internalMsg string, args ...any) error

Create new *MisoErr to wrap the cause error

if cause is nil, nil is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL