errors

package module
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: MIT Imports: 7 Imported by: 35

Documentation

Overview

Package errors provides a means to return detailed information for a request error, typically encoded in JSON format. This package wraps standard library error handling features and offers additional stack trace capabilities.

Package errors provides the error functions

Index

Constants

View Source
const (
	Success = Code(0)
	Error   = Code(1)
)
View Source
const (
	UnsupportedError = String("unsupported error")
)

Variables

View Source
var (
	// Append is a helper function that will append more merr
	Append = merr.Append
	// ListFormatFunc is a helper function that will format the merr
	ListFormatFunc = merr.ListFormatFunc
)

Functions

func As

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

As determines if the error can be assigned to a specific type.

func Cause added in v0.0.3

func Cause(err error) error

Cause returns the root cause of the error.

func CodeString added in v0.0.6

func CodeString(code Code) string

func ErrorFormatJSON added in v0.0.3

func ErrorFormatJSON(i []error) string

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf creates a new error with a formatted message.

func Is

func Is(err, target error) bool

Is checks if the error matches a target error.

func Join

func Join(errs ...error) error

Join joins multiple errors into one.

func Must added in v0.0.6

func Must[T any](v T, err error) T

Must panics if the error is not nil.

func New

func New(message string) error

New creates a new error with the given message.

func RegisterCode

func RegisterCode(code Code, val string)

func Stack

func Stack(v string) error

Stack creates an error with a stack trace from the provided string.

func Stackf

func Stackf(format string, args ...interface{}) error

Stackf formats a string and creates an error with a stack trace.

func Unwrap

func Unwrap(err error) error

Unwrap unwraps the error to its underlying cause.

func WithStack added in v0.0.3

func WithStack(err error) error

WithStack attaches a stack trace to an existing error.

func Wrap

func Wrap(err error, message string) error

Wrap wraps an existing error with a new message.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf formats a string and wraps an existing error with a new message.

Types

type Code added in v0.0.6

type Code int

func ErrInteger added in v0.0.6

func ErrInteger(err int) Code

ErrInteger creates a new error from a string

func (Code) Code added in v0.0.6

func (obj Code) Code() int

func (Code) Error added in v0.0.6

func (obj Code) Error() string

func (Code) Is added in v0.0.6

func (obj Code) Is(err error) bool

Is checks whether the error is equal to the

func (Code) String added in v0.0.6

func (obj Code) String() string

type ErrorFormatFunc

type ErrorFormatFunc = merr.ErrorFormatFunc

ErrorFormatFunc is a helper function that will format the merr

type MultiError

type MultiError = merr.Error

MultiError is an alias of `github.com/hashicorp/go-multierror`.Error

type String added in v0.0.3

type String string

func ErrString deprecated added in v0.0.3

func ErrString(err string) String

ErrString creates a new error from a string

Deprecated: use errors.NewString instead

func NewString added in v0.0.6

func NewString(message string) String

NewString creates a new error from a string

func (String) Error added in v0.0.3

func (obj String) Error() string

Error returns the JSON representation of the error

func (String) Is added in v0.0.3

func (obj String) Is(err error) bool

Is checks whether the error is equal to the

func (String) String added in v0.0.3

func (obj String) String() string

String returns the JSON representation of the error

type ThreadSafeMultiError

type ThreadSafeMultiError struct {
	ErrorFormat ErrorFormatFunc
	// contains filtered or unexported fields
}

ThreadSafeMultiError represents a collection of merr

func ThreadSafe

func ThreadSafe(err error, fns ...ErrorFormatFunc) *ThreadSafeMultiError

ThreadSafe creates a new ThreadSafeMultiError collection

func (*ThreadSafeMultiError) Append

func (e *ThreadSafeMultiError) Append(err error)

Append adds an error to the MultiError collection

func (*ThreadSafeMultiError) Error

func (e *ThreadSafeMultiError) Error() string

Error returns the JSON representation of the MultiError collection

func (*ThreadSafeMultiError) Errors

func (e *ThreadSafeMultiError) Errors() []error

Errors returns the merr collection

func (*ThreadSafeMultiError) Has

func (e *ThreadSafeMultiError) Has(err any) error

Has checks if the MultiError collection has the given merr or not

func (*ThreadSafeMultiError) HasErrors

func (e *ThreadSafeMultiError) HasErrors() bool

HasErrors checks if the MultiError collection has any merr

func (*ThreadSafeMultiError) Unsafe

func (e *ThreadSafeMultiError) Unsafe() *MultiError

Unsafe returns the MultiError collection

type Valuer added in v0.0.6

type Valuer[T any] interface {
	Value() T          // Value returns the encapsulated value.
	Error() string     // Error returns the string representation of the error, satisfying the error interface.
	Unwrap() error     // Unwrap returns the original error object.
	Is(err error) bool // Is determines if the current error was created by the given error.
}

Valuer defines an interface for retrieving encapsulated values and error information. It provides a unified way to access different types of values and error information.

func Valued added in v0.0.6

func Valued[T any](v T, err error) Valuer[T]

Valued is a generic function that creates a Valuer interface object encapsulating a value and an error. Parameters:

v - The value to be encapsulated.
err - The original error to be encapsulated.

Returns:

An object implementing the Valuer interface, encapsulating the given value and error.

Directories

Path Synopsis
Package rpcerr provides a way to return detailed information for an RPC request error.
Package rpcerr provides a way to return detailed information for an RPC request error.

Jump to

Keyboard shortcuts

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