gasket

package module
v0.0.0-...-ccdf5f0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const NilText = "gasket: nil"

Variables

Functions

This section is empty.

Types

type CodeHinter

type CodeHinter interface {
	// Gets the type's code.
	Code() int
}

type Error

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

func HasCode

func HasCode(err error, code int) *Error

If somewhere on the error chain, gasket.(*Error) exists, and have the given code, returns that gasket.(*Error), otherwise returns nil.

func Wrap

func Wrap(err error) *Error

Wraps error with extra informations.

If error is a type of gasket.Error (more superficially implements types.CodeHinter), it will take the code from the type.

func (Error) As

func (e Error) As(err any) bool

func (Error) Code

func (e Error) Code() int

Implements CodeHinter interface.

Returns the Error Code.

func (Error) Context

func (e Error) Context() map[string]any

Returns the context of the error.

func (Error) Display

func (e Error) Display() string

Human readable output.

func (Error) Error

func (e Error) Error() string

func (Error) Is

func (e Error) Is(err error) bool

func (Error) IsNil

func (e Error) IsNil() bool

func (Error) MarshalJSONObject

func (e Error) MarshalJSONObject(enc *gojay.Encoder)

func (Error) Message

func (e Error) Message() string

Returns the error's message.

func (*Error) SetCode

func (e *Error) SetCode(code int) *Error

Set the code for error (and thus what types.CodeHinter interface will return).

func (*Error) SetContext

func (e *Error) SetContext(values ...any) *Error

Sets the error context.

Values must be alternating between string and other values, with even index as string. If value is not of type string, it will be coerced to string using fmt.Sprintf.

Values must be at least of Length of two, otherwise it will be ignored.

Example:

err.SetContext("key", value, "key2", value2)

func (*Error) SetMessage

func (e *Error) SetMessage(msg string) *Error

Set message for current error.

func (Error) String

func (e Error) String() string

func (Error) Unwrap

func (e Error) Unwrap() error

Returns the wrapped error.

func (Error) WriteDisplay

func (e Error) WriteDisplay(s types.StringWriter)

Collect accumulated Human Readable output to s. Ignore must not be returned, nor does it should panic, because this is just intended for human read.

Interface implementer will not return how much bytes written or error.

So ensure the Writer is reliable and can consume everything without error, e.g. bytes.Buffer or strings.Builder.

func (Error) WriteError

func (e Error) WriteError(sw io.StringWriter)

type ErrorWriter

type ErrorWriter interface {
	WriteError(sw io.StringWriter)
}

Jump to

Keyboard shortcuts

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