errors

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default special error type. If it's wrapping another error, then it will take the type of that error if it's an Error. Otherwise, it equates to Internal.
	Default = register(nil)

	SubtaskErr   = register(&Type{meta: "subtask"})
	NotFound     = register(&Type{httpCode: http.StatusNotFound, meta: "not-found"})
	BadInput     = register(&Type{httpCode: http.StatusBadRequest, meta: "bad-input"})
	Unauthorized = register(&Type{httpCode: http.StatusUnauthorized, meta: "unauthorized"})
	Forbidden    = register(&Type{httpCode: http.StatusForbidden, meta: "forbidden"})
	Internal     = register(&Type{httpCode: http.StatusInternalServerError, meta: "internal"})
	Timeout      = register(&Type{httpCode: http.StatusGatewayTimeout, meta: "timeout"})
)

Supported error types

Functions

This section is empty.

Types

type Error

type Error interface {

	// Messages the message associated with this Error.
	Messages() Messages
	// GetType gets the Type of this error
	GetType() *Type
	// As Attempts to cast this Error to the requested Type, and returns nil if it can't.
	As(*Type) Error
	// GetData returns the data associated with this Error (may be nil)
	GetData() interface{}
	// contains filtered or unexported methods
}

Error The interface that all internally managed errors should adhere to.

func AsLakeErrorType added in v0.14.0

func AsLakeErrorType(err error) Error

AsLakeErrorType attempts to cast err to Error, otherwise returns nil

func Convert added in v0.14.0

func Convert(err error) Error

Convert converts a raw error to an Error. Similar to Type.WrapRaw with a type of Default, but will not wrap the error if it's already of type Error. Passing in nil will return nil.

func Convert00001 added in v0.14.0

func Convert00001[T1 any, T2 any, T3 any, T4 any](t1 T1, t2 T2, t3 T3, t4 T4, err error) (T1, T2, T3, T4, Error)

Convert00001 like Convert01, but with four extra args

func Convert0001 added in v0.14.0

func Convert0001[T1 any, T2 any, T3 any](t1 T1, t2 T2, t3 T3, err error) (T1, T2, T3, Error)

Convert0001 like Convert01, but with three extra args

func Convert001 added in v0.14.0

func Convert001[T1 any, T2 any](t1 T1, t2 T2, err error) (T1, T2, Error)

Convert001 like Convert01, but with two extra args

func Convert01 added in v0.14.0

func Convert01[T1 any](t1 T1, err error) (T1, Error)

Convert01 an extension of Convert that allows passing in one extra arg. Useful for inlining the conversion of multivalued returns.

type MessageType added in v0.14.0

type MessageType int

MessageType the type of message for an Error

type Messages added in v0.14.0

type Messages []*errMessage

Messages alias for messages of an Error

func (Messages) Causes added in v0.14.0

func (m Messages) Causes() []string

Causes gets the non-main messages of the Messages in causal sequence

func (Messages) Format added in v0.14.0

func (m Messages) Format() string

Format formats the messages into a single string

func (Messages) Get added in v0.14.0

func (m Messages) Get() string

Get gets the main (top-level) (or first non-empty message if exists) message of the Messages

type Option added in v0.14.0

type Option func(*options)

Option add customized properties to the Error

func WithData added in v0.14.0

func WithData(data interface{}) Option

WithData associate data with this Error

type Type added in v0.14.0

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

Type error are constructed from these, and they contain metadata about them.

func HttpStatus added in v0.14.0

func HttpStatus(code int) *Type

func (*Type) Combine added in v0.14.0

func (t *Type) Combine(errs []error) Error

Combine constructs a new Error from combining multiple errors. Stacktrace info for each of the errors will not be present in the result, so it's best to log the errors before combining them.

func (*Type) GetHttpCode added in v0.14.0

func (t *Type) GetHttpCode() int

GetHttpCode gets the associated Http code with this Type, if explicitly set, otherwise http.StatusInternalServerError

func (*Type) New added in v0.14.0

func (t *Type) New(message string, opts ...Option) Error

New constructs a new Error instance with this message

func (*Type) Wrap added in v0.14.0

func (t *Type) Wrap(err error, message string, opts ...Option) Error

Wrap constructs a new Error instance with this message and wraps the passed in error. A nil 'err' will return a nil Error.

func (*Type) WrapRaw added in v0.14.0

func (t *Type) WrapRaw(err error) Error

WrapRaw constructs a new Error instance that directly wraps this error with no additional context. A nil 'err' will return a nil Error. This additional wrapping will create an additional nested stacktrace on this line if the setting is enabled.

Jump to

Keyboard shortcuts

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