errors

package
v0.18.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 1 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As added in v0.13.0

func As(err error, target interface{}) bool

As wraps errors.As. Check errors.As for more information.

func Is added in v0.13.0

func Is(err, target error) bool

Is wraps errors.Is. Check errors.Is for more information.

func New

func New(message, layer string, code int) error

New creates a new Error.

func Unwrap added in v0.13.0

func Unwrap(err error) error

Unwrap returns the next error from the error tree.

func WithData

func WithData(parent error, data Data) error

WithData insiert Data into parent is from type Error.

func Wrap

func Wrap(err error, next error) error

Wrap wraps an error with another error.

It is a interface for errors.Join. Check errors.Join for more information.

Types

type Data

type Data interface{}

Data is a custom type to carry error's metadata. It can be any data type, but a struct is recommended due its fine control on JSON marshalling for each field.

type Error

type Error struct {
	// message is the error message.
	Message string `json:"message"`
	// Layer is the error layer.
	Layer string `json:"layer,omitempty"`
	// Code is the error code.
	Code int `json:"code,omitempty"`
	// Data is the error metadata.
	Data Data `json:"data,omitempty"`
}

Error is a custom error that carry attributes to specify error's message, resource, layer, code and data.

func (Error) Error

func (e Error) Error() string

Jump to

Keyboard shortcuts

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