dasherr

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package dasherr

充分拓展后的错误类

Fully expanded error class

Index

Constants

View Source
const (
	CodeOK                 = uint32(0)           //成功
	CodeUnknown            = 9999 + uint32(iota) //未知错误
	CodeCanceled                                 // 操作被取消
	CodeInvalidArgument                          // 无效参数
	CodeDeadlineExceeded                         // 操作超过截止日期
	CodeNotFound                                 // 请求实体未找到
	CodeAlreadyExists                            // 请求实体已存在
	CodePermissionDenied                         // 权限拒绝
	CodeResourceExhausted                        // 资源已经耗尽
	CodeFailedPrecondition                       // 先决条件失败
	CodeAborted                                  // 操作已中止
	CodeOutOfRange                               // 操作值溢出
	CodeUnimplemented                            // 未实现操作
	CodeInternal                                 // 内部错误
	CodeUnavailable                              // 服务当前不可用
	CodeDataLoss                                 // 数据丢失或损坏
	CodeUnauthenticated                          // 未认证或凭证无效
	CodeExternalGrpcError                        // 外部通信错误
	CodeMax                = 19999               // Dasherr Max Code
)

常规错误码 errdash code [10000~20000)

Variables

This section is empty.

Functions

func GetCodeMsg

func GetCodeMsg(code uint32) string

GetCodeMsg @Editor robotyang at 2023

GetCodeMsg 转义 code 为对应中文含义

@Param code 可能是 grpc code、errdash code 的 uint32 或 codes.Code;

func ParseCode

func ParseCode(code any) uint32

ParseCode @Editor robotyang at 2023

ParseCode 解析 code 对应的 errdash code

@Param code 可能是 grpc code、errdash code 的 uint32 或 codes.Code;

func RegisterCode

func RegisterCode(dict map[uint32]string)

RegisterCode @Editor robotyang at 2023

RegisterCode 注册错误字典

@Param dict 要注册的错误字段(建议尽量注册 >= 20000 的 code)

Types

type Dasherr

type Dasherr struct {
	Pres  string   //错误信息前缀
	Codes uint32   //错误码
	Msgs  string   //错误信息(用户看)
	Logs  []string //日志信息(开发看)
	Stack []string //调用堆栈(开发看)
}

Dasherr error struct

func Code

func Code(code uint32) *Dasherr

Code @Editor robotyang at 2023

Code is a ...

func Err

func Err(err ...error) *Dasherr

Err @Editor robotyang at 2023

Err is a ...

func Log

func Log(log string) *Dasherr

Log @Editor robotyang at 2023

Log is a ...

func Logf

func Logf(format string, a ...any) *Dasherr

Logf @Editor robotyang at 2023

Logf is a ...

func Msg

func Msg(msg string) *Dasherr

Msg @Editor robotyang at 2023

Msg is a ...

func Msgf

func Msgf(format string, a ...any) *Dasherr

Msgf @Editor robotyang at 2023

Msgf is a ...

func New

func New(err ...error) *Dasherr

New @Editor robotyang at 2023

New 实例化错误类

func Pre

func Pre(msg string) *Dasherr

Pre @Editor robotyang at 2023

Pre is a ...

func Pref

func Pref(format string, a ...any) *Dasherr

Pref @Editor robotyang at 2023

Pref is a ...

func (*Dasherr) Code

func (m *Dasherr) Code(code uint32) *Dasherr

Code @Editor robotyang at 2023

Code 设置错误码

func (*Dasherr) Err

func (m *Dasherr) Err(err error) *Dasherr

Err @Editor robotyang at 2023

Err is a ...

func (*Dasherr) Error

func (m *Dasherr) Error() string

Error @Editor robotyang at 2023

Error 必须实现的接口

func (*Dasherr) Log

func (m *Dasherr) Log(log string) *Dasherr

Log @Editor robotyang at 2023

Log 设置 日志消息(开发看)

func (*Dasherr) Logf

func (m *Dasherr) Logf(format string, a ...any) *Dasherr

Logf @Editor robotyang at 2023

Logf 设置 日志消息(开发看)

func (*Dasherr) Msg

func (m *Dasherr) Msg(msg string) *Dasherr

Msg @Editor robotyang at 2023

Msg 设置 错误消息(用户看)

func (*Dasherr) Msgf

func (m *Dasherr) Msgf(format string, a ...any) *Dasherr

Msgf @Editor robotyang at 2023

Msgf 设置 错误消息(用户看)

func (*Dasherr) Pre

func (m *Dasherr) Pre(prefix string) *Dasherr

Pre @Editor robotyang at 2023

Pre is a ...

func (*Dasherr) Pref

func (m *Dasherr) Pref(format string, a ...any) *Dasherr

Pref @Editor robotyang at 2023

Pref is a ...

type RpcError

type RpcError interface {
	GRPCStatus() *status.Status
}

Jump to

Keyboard shortcuts

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