Documentation ¶
Index ¶
- Constants
- Variables
- func As(err error, label error) error
- func ErrIfNil[T any](t T, err error) (T, error)
- func ErrInternalBy(err error) error
- func ErrInternalByWith(label string, err error) error
- func ErrInternalByWithContext(ctx context.Context, err error) error
- func ErrInternalByWithContextAndError(ctx context.Context, label, err error) error
- func ErrInternalByWithContextAndLabel(ctx context.Context, label string, err error) error
- func ErrInternalByWithError(label, err error) error
- func Is(err error, label error) bool
- func IsInternal(err error) bool
- func Localize(l *i18n.Localizer, err error) error
- func OrInternal[T comparable](v T, err error) (r T, _ error)
- func OrInternalWith[T comparable](ctx context.Context, v T, err error) (r T, _ error)
- func PretifyStack(r io.Reader, w io.Writer)
- func Stack() string
- func UnwrapErrInternal(err error) error
- func UnwrapErrInternalOr(err error) error
- func With(label error) func(error) *Error
- type E
- type Error
- type Localizable
- type Localizer
- type W
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 ¶
As looks up errors whose label is the same as the specific label and return a wrapped error.
func ErrInternalBy ¶
func ErrInternalByWith ¶
func ErrInternalByWithError ¶
func Is ¶
Is looks up errors whose label is the same as the specific label and return true if it was found
func IsInternal ¶
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 UnwrapErrInternal ¶
func UnwrapErrInternalOr ¶
Types ¶
type Error ¶
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.
type Localizable ¶
Click to show internal directories.
Click to hide internal directories.