rerror

package
v0.0.0-...-5cbc45b Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 16 Imported by: 26

Documentation

Index

Constants

View Source
const (
	IDErrInternal       = "internal"
	IDErrNotFound       = "not found"
	IDErrAlreadyExists  = "already exists"
	IDErrInvalidParams  = "invalid params"
	IDErrNotImplemented = "not implemented"
)

Variables

View Source
var (

	// ErrNotFound indicates something was not found.
	ErrNotFound = WrapE(&i18n.Message{ID: IDErrNotFound}, ErrNotFoundRaw)
	// ErrAlreadyExists indicates something was already exists.
	ErrAlreadyExists = WrapE(&i18n.Message{ID: IDErrAlreadyExists}, ErrAlreadyExistsRaw)
	// ErrInvalidParams represents the params are invalid, such as empty string.
	ErrInvalidParams = WrapE(&i18n.Message{ID: IDErrInvalidParams}, ErrInvalidParamsRaw)
	// ErrNotImplemented indicates unimplemented.
	ErrNotImplemented = WrapE(&i18n.Message{ID: IDErrNotImplemented}, ErrNotImplementedRaw)

	ErrNotFoundRaw       = errors.New("not found")
	ErrAlreadyExistsRaw  = errors.New("already exists")
	ErrInvalidParamsRaw  = errors.New("invalid params")
	ErrNotImplementedRaw = errors.New("not implemented")
)

Functions

func As

func As(err error, label error) error

As looks up errors whose label is the same as the specific label and return a wrapped error.

func ErrIfNil

func ErrIfNil[T any](t T, err error) (T, error)

func ErrInternalBy

func ErrInternalBy(err error) error

func ErrInternalByWith

func ErrInternalByWith(label string, err error) error

func ErrInternalByWithContext

func ErrInternalByWithContext(ctx context.Context, err error) error

func ErrInternalByWithContextAndError

func ErrInternalByWithContextAndError(ctx context.Context, label, err error) error

func ErrInternalByWithContextAndLabel

func ErrInternalByWithContextAndLabel(ctx context.Context, label string, err error) error

func ErrInternalByWithError

func ErrInternalByWithError(label, err error) error

func Is

func Is(err error, label error) bool

Is looks up errors whose label is the same as the specific label and return true if it was found

func IsInternal

func IsInternal(err error) bool

func Localize

func Localize(l *i18n.Localizer, err error) error

func OrInternal

func OrInternal[T comparable](v T, err error) (r T, _ error)

func OrInternalWith

func OrInternalWith[T comparable](ctx context.Context, v T, err error) (r T, _ error)

func PretifyStack

func PretifyStack(r io.Reader, w io.Writer)

func Stack

func Stack() string

func UnwrapErrInternal

func UnwrapErrInternal(err error) error

func UnwrapErrInternalOr

func UnwrapErrInternalOr(err error) error

func With

func With(label error) func(error) *Error

With returns a new constructor to generate an Error with specific label.

Types

type E

type E struct {
	// contains filtered or unexported fields
}

func FmtE

func FmtE(m *i18n.Message, args ...any) *E

func NewE

func NewE(m *i18n.Message) *E

func WrapE

func WrapE(m *i18n.Message, err error) *E

func (*E) Error

func (e *E) Error() string

func (*E) LocalizeError

func (e *E) LocalizeError(l *i18n.Localizer) error

func (*E) Unwrap

func (e *E) Unwrap() error

type Error

type Error struct {
	Label    error
	Err      error
	Hidden   bool
	Separate bool
}

Error can hold an error together with label. This is useful for displaying a hierarchical error message cleanly and searching by label later to retrieve a wrapped error. Currently, Go standard error library does not support these use cases. That's why we need our own error type.

func Fmt

func Fmt(format string, a ...any) *Error

func From

func From(label string, err error) *Error

From creates an Error with string label.

func FromSep

func FromSep(label string, err error) *Error

From creates an Error with string label, but separated from wrapped error message when the error is printed.

func Get

func Get(err error) *Error

Get gets Error struct from an error

func (*Error) Error

func (e *Error) Error() string

Error implements error interface.

func (*Error) LocalizeError

func (e *Error) LocalizeError(l *i18n.Localizer) error

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements the interface for errors.Unwrap.

type Localizable

type Localizable interface {
	LocalizeError(*i18n.Localizer) error
}

type Localizer

type Localizer struct {
	// contains filtered or unexported fields
}

func NewLocalizer

func NewLocalizer(err error, l *i18n.Localizer) *Localizer

func (*Localizer) Error

func (l *Localizer) Error() string

type W

type W struct {
	Msg string
	Err error
}

W simply wraps an error, without printing it.

func (*W) Error

func (w *W) Error() string

func (*W) Unwrap

func (w *W) Unwrap() error

Jump to

Keyboard shortcuts

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