errors

package
v0.28.20260918133308 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 3 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Is = errors.Is

Functions

func Catch

func Catch(e error, action Action) bool

func ErrorFormat added in v0.28.20240114140844

func ErrorFormat(e error, format ...ErrFormat) (s string)

按格式显示err

默认使用ErrSimplifyFunc 即 e.Error() + "\n"

func Join added in v0.28.20240114140844

func Join(e ...error) error

func Unwrap added in v0.28.20240114140844

func Unwrap(e error) []error

Types

type Action added in v0.28.20250120132246

type Action string

func (Action) Append added in v0.28.20250120153835

func (t Action) Append(child string) Action

func (Action) Catch added in v0.28.20250327131507

func (t Action) Catch(e error) bool

func (Action) Error added in v0.28.20250211194255

func (t Action) Error() string

func (Action) New added in v0.28.20250120183746

func (t Action) New(reason ...string) (e Error)

func (Action) NewErr added in v0.28.20250614175334

func (t Action) NewErr(err ...error) (e error)

func (Action) Unwrap added in v0.28.20250326143542

func (t Action) Unwrap() []error

type ErrFormat added in v0.28.20240903115607

type ErrFormat func(e error) string
var (
	// e.Error() + "\n"
	ErrSimplifyFunc ErrFormat = func(e error) string {
		return e.Error() + "\n"
	}
	// 如是action,则 string(err.action) + ":" + e.Error() + "\n"
	//
	// 否则e.Error() + "\n"
	ErrActionSimplifyFunc ErrFormat = func(e error) string {
		if err, ok := e.(Error); ok && string(err.action) != err.Reason {
			return string(err.action) + ":" + e.Error() + "\n"
		} else {
			return e.Error() + "\n"
		}
	}
	// "> " + e.Error() + " "
	ErrInLineFunc ErrFormat = func(e error) string {
		return "> " + e.Error() + " "
	}
	// 如是action,则 "> " + string(err.action) + ":" + e.Error() + " "
	//
	// 否则"> " + e.Error() + " "
	ErrActionInLineFunc ErrFormat = func(e error) string {
		if err, ok := e.(Error); ok && string(err.action) != err.Reason {
			return fmt.Sprintf("> %v:%v ", err.action, strings.TrimSpace(e.Error()))
		} else {
			return fmt.Sprintf("> %v ", strings.TrimSpace(e.Error()))
		}
	}
)

type Error

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

func New

func New(reason string, action ...Action) (e Error)

func (Error) Error

func (t Error) Error() string

func (Error) Is added in v0.28.20250120183746

func (t Error) Is(e error) bool

func (Error) Unwrap added in v0.28.20250120183746

func (t Error) Unwrap() error

func (Error) WithReason added in v0.28.20240325172911

func (t Error) WithReason(reason string) Error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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