gerror

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause returns the root cause error of `err`.

func Current

func Current(err error) error

Current creates and returns the current level error. It returns nil if current level error is nil.

func Equal

func Equal(err, target error) bool

Equal reports whether current error `err` equals to error `target`. Please note that, in default comparison logic for `Error`, the errors are considered the same if both the `code` and `text` of them are the same.

func HasError

func HasError(err, target error) bool

HasError is alias of Is, which more easily understanding semantics.

func HasStack

func HasStack(err error) bool

HasStack checks and reports whether `err` implemented interface `gerror.IStack`.

func Is

func Is(err, target error) bool

Is reports whether current error `err` has error `target` in its chaining errors. It is just for implements for stdlib errors.Is from Go version 1.17.

func New

func New(text string) error

New creates and returns an error which is formatted from given text.

func NewSkip

func NewSkip(skip int, text string) error

NewSkip creates and returns an error which is formatted from given text. The parameter `skip` specifies the stack callers skipped amount.

func NewSkipf

func NewSkipf(skip int, format string, args ...interface{}) error

NewSkipf returns an error that formats as the given format and args. The parameter `skip` specifies the stack callers skipped amount.

func Newf

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

Newf returns an error that formats as the given format and args.

func Stack

func Stack(err error) string

Stack returns the stack callers as string. It returns the error string directly if the `err` does not support stacks.

func Unwrap

func Unwrap(err error) error

Unwrap returns the next level error. It returns nil if current level error or the next level error is nil.

func Wrap

func Wrap(err error, text string) error

Wrap wraps error with text. It returns nil if given err is nil. Note that it does not lose the error code of wrapped error, as it inherits the error code from it.

func WrapSkip

func WrapSkip(skip int, err error, text string) error

WrapSkip wraps error with text. It returns nil if given err is nil. The parameter `skip` specifies the stack callers skipped amount. Note that it does not lose the error code of wrapped error, as it inherits the error code from it.

func WrapSkipf

func WrapSkipf(skip int, err error, format string, args ...interface{}) error

WrapSkipf wraps error with text that is formatted with given format and args. It returns nil if given err is nil. The parameter `skip` specifies the stack callers skipped amount. Note that it does not lose the error code of wrapped error, as it inherits the error code from it.

func Wrapf

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

Wrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier. It returns nil if given `err` is nil. Note that it does not lose the error code of wrapped error, as it inherits the error code from it.

Types

type Error

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

Error is custom error for additional features.

func (*Error) Cause

func (err *Error) Cause() error

Cause returns the root cause error.

func (*Error) Current

func (err *Error) Current() error

Current creates and returns the current level error. It returns nil if current level error is nil.

func (*Error) Equal

func (err *Error) Equal(target error) bool

Equal reports whether current error `err` equals to error `target`. Please note that, in default comparison for `Error`, the errors are considered the same if both the `code` and `text` of them are the same.

func (*Error) Error

func (err *Error) Error() string

Error implements the interface of Error, it returns all the error as string.

func (*Error) Is

func (err *Error) Is(target error) bool

Is reports whether current error `err` has error `target` in its chaining errors. It is just for implements for stdlib errors.Is from Go version 1.17.

func (*Error) Unwrap

func (err *Error) Unwrap() error

Unwrap is alias of function `Next`. It is just for implements for stdlib errors.Unwrap from Go version 1.17.

Jump to

Keyboard shortcuts

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