xerror

package
v0.0.0-...-b147793 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Overview

Package xerror 错误处理( error ) 相关的功能,是对标准库 errors 的补充

Index

Constants

This section is empty.

Variables

View Source
var (
	// NotFound 错误:数据找不到
	NotFound = NewCodeError(1000, "not found")

	// InvalidStatus 错误:数据的状态非正常
	InvalidStatus = NewCodeError(1001, "invalid status")

	// InvalidParam 错误:无效的请求参数
	InvalidParam = NewCodeError(1002, "invalid param")
)

Functions

func ErrCode

func ErrCode(err error) (int64, bool)

func ErrCode2

func ErrCode2(err error, def int64) int64

func IsInvalidParam

func IsInvalidParam(err error) bool

IsInvalidParam 判断是否参数不对的错误

func IsNotFound

func IsNotFound(err error) bool

IsNotFound 判断是否资源不存在错误

Types

type Chan

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

func (*Chan) Send

func (e *Chan) Send(err error)

func (*Chan) Watch

func (e *Chan) Watch() <-chan error

type CodeError

type CodeError interface {
	error
	HasErrCode
}

func NewCodeError

func NewCodeError(code int64, msg string) CodeError

func WithCode

func WithCode(err error, code int64) CodeError

type HasErrCode

type HasErrCode interface {
	ErrCode() int64
}

type NotExistsError

type NotExistsError interface {
	NotExists() bool
}

type OnceSet

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

OnceSet 只允许设置一次的用于存储 error 信息的对象

func (*OnceSet) Clear

func (o *OnceSet) Clear()

Clear 清除存储的值和状态,调用后再次调用 SetOnce 可成功存储

func (*OnceSet) Error

func (o *OnceSet) Error() string

func (*OnceSet) Replace

func (o *OnceSet) Replace(err error)

Replace 强制替换值,不判断是否存储过

func (*OnceSet) SetOnce

func (o *OnceSet) SetOnce(err error) bool

SetOnce 存储 error,当没有存储过则成功,否则失败

func (*OnceSet) Unwrap

func (o *OnceSet) Unwrap() error

Unwrap 返回底层存储的 error

type TraceError

type TraceError interface {
	error
	TraceData() map[string]any
}

Jump to

Keyboard shortcuts

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