Documentation
¶
Index ¶
- func As(err error, target any) bool
- func Cause(err error) error
- func DecodeError(ctx context.Context, enc errors.EncodedError) error
- func EncodeError(ctx context.Context, err error) errors.EncodedError
- func FlattenHints(err error) string
- func GetAllHints(err error) []string
- func GetCode(err error) int
- func GetGrpcCode(err error) codes.Code
- func GetHint(err error) string
- func GetHttpCode(err error, defaultCode int) int
- func GetStack(err error) []string
- func GetStackTrace(err error) errbase.StackTrace
- func Is(err, target error) bool
- func Join(errs ...error) error
- func New(msg string) error
- func NewBiz(code int, hint string, msg string) error
- func NewBizf(code int, hint string, format string, args ...any) error
- func NewWithCode(code int, msg string) error
- func NewWithCodef(code int, format string, args ...any) error
- func Newf(format string, args ...any) error
- func Unwrap(err error) error
- func WithCode(err error, code int) error
- func WithGrpcCode(err error, code codes.Code) error
- func WithHint(err error, hint string) error
- func WithHintf(err error, format string, args ...any) error
- func WithHttpCode(err error, code int) error
- func WithMessage(err error, msg string) error
- func WithMessagef(err error, format string, args ...any) error
- func WithStack(err error) error
- func Wrap(err error, msg string) error
- func Wrapf(err error, format string, args ...any) error
- type ErrorMarshal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeError ¶
func DecodeError(ctx context.Context, enc errors.EncodedError) error
DecodeError 解码错误,还原错误类型
func EncodeError ¶
func EncodeError(ctx context.Context, err error) errors.EncodedError
EncodeError 将err进行编码,编码后为一个基于protobuf生成的结构体,主要用于跨网络进行错误传输
func GetStackTrace ¶
func GetStackTrace(err error) errbase.StackTrace
GetStackTrace 获取错误中的堆栈信息,若错误为链式错误,则使用最外层错误的堆栈信息,以保证错误堆栈覆盖生效 errbase.StackTrace 实际上是 pkg/errors中的StackTrace,主流日志库均可友好打印堆栈信息
func NewBiz ¶
NewBiz 快速创建一个业务错误,业务错误一般包含错误信息、状态码及提示信息, 业务错误一般为前置判断异常,故http状态码默认为200,grpc状态码默认为 codes.FailedPrecondition
func NewBizf ¶
NewBizf 使用格式化字符串创建一个业务错误,业务错误一般包含错误信息、状态码及提示信息, 业务错误一般为前置判断异常,故http状态码默认为200,grpc状态码默认为 codes.FailedPrecondition
func NewWithCodef ¶
NewWithCodef 使用格式化方式创建带有业务状态码的错误
func WithMessagef ¶
WithMessagef 使用格式化字符串为错误附加上下文信息
Types ¶
type ErrorMarshal ¶
func (ErrorMarshal) MarshalJSON ¶
func (e ErrorMarshal) MarshalJSON() ([]byte, error)
func (ErrorMarshal) MarshalText ¶
func (e ErrorMarshal) MarshalText() ([]byte, error)
Click to show internal directories.
Click to hide internal directories.