erro

package
v1.0.4-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package erro 收拢了所有的错误类型,错误溯源类型等 1. 支持打印不同该类型的错误的详细提示, 方便确定问题的解决方法 2. 异常可以溯源, 方便问题排查

Index

Constants

This section is empty.

Variables

View Source
var GcFlags = NewRequiredBuildFlagsError("-gcflags=\"all=-l\"")

GcFlags 编译标记,取消函数内联

View Source
var LdFlags = NewRequiredBuildFlagsError("-ld=flags=\"-s=false\"")

LdFlags 编译标记,取消符号压缩

Functions

func Cause added in v1.0.5

func Cause(err error) error

Cause 获取错误原因,err对象需要实现Traceable接口才能获取并返回cause error, 否则一律返回false

func CauseBy added in v1.0.5

func CauseBy(err error, traceAbleError Traceable) bool

CauseBy 判断错误是否由指定的异常引起,err对象需要实现Traceable接口才能被追踪, 否则一律返回false err 判断目标异常 traceAbleError 指定的异常原因

func NewArgNotFoundError

func NewArgNotFoundError(funcName string, index int) error

NewArgNotFoundError 函数未找到 funcName 函数名称 index 参数下标

func NewArgsNotMatchError

func NewArgsNotMatchError(funcDef interface{}, argLen int, expectLen int) error

NewArgsNotMatchError 创建参数异常 funcDef 函数定义 argLen 参数长度 expectLen 期望长度

func NewFieldNotFoundError

func NewFieldNotFoundError(typName string, fieldName string) error

NewFieldNotFoundError 创建类型未找到异常 typName 类型名称 fieldName 属性名称

func NewFuncNotFoundError

func NewFuncNotFoundError(funcName string) error

NewFuncNotFoundError 函数未找到 funcName 函数名称

func NewFuncNotFoundErrorWithSuggestion

func NewFuncNotFoundErrorWithSuggestion(funcName string, suggestions []string) error

NewFuncNotFoundErrorWithSuggestion 函数未找到并给出提示 funcName 函数名称

func NewIllegalCallError

func NewIllegalCallError(funcName string, paramName string, paramValue string) error

NewIllegalCallError 创建参数异常 funcName 函数名 paramName 参数名 paramValue 参数值

func NewIllegalParamCError

func NewIllegalParamCError(paramName string, paramValue string, cause error) error

NewIllegalParamCError 创建参数异常 paramName 参数名 paramValue 参数值

func NewIllegalParamError

func NewIllegalParamError(paramName string, paramValue string) error

NewIllegalParamError 创建参数异常 paramName 参数名 paramValue 参数值

func NewIllegalParamTypeError

func NewIllegalParamTypeError(paramName string, paramType, expectType string) error

NewIllegalParamTypeError 创建参数类型异常 paramName 参数名 paramType 参数类型 expectType 期望类型

func NewIllegalStatusError

func NewIllegalStatusError(funcName string, msg string) error

NewIllegalStatusError 状态参数异常 funcName 函数名 msg 信息

func NewReturnParamNotFoundError

func NewReturnParamNotFoundError(funcName string, index int) error

NewReturnParamNotFoundError 函数未找到 funcName 函数名称 index 返回值下标

func NewReturnsNotMatchError

func NewReturnsNotMatchError(funcDef interface{}, argLen int, expectLen int) error

NewReturnsNotMatchError 创建参数异常 funcDef 函数定义 argLen 参数长度 expectLen 期望长度

func NewTraceableError

func NewTraceableError(err error, cause error) error

NewTraceableError 通过 error, cause 描述创建可跟踪的错误

func NewTraceableErrorc added in v1.0.5

func NewTraceableErrorc(errStr string, cause error) error

NewTraceableErrorc 通过 string, cause 描述创建可跟踪的错误

func NewTraceableErrors added in v1.0.5

func NewTraceableErrors(errStr string) error

NewTraceableErrors 通过 string 描述创建可跟踪的错误

func NewTypeNotFoundError

func NewTypeNotFoundError(typName string) error

NewTypeNotFoundError 创建类型未找到异常 typName 类型名称

Types

type ArgNotFound

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

ArgNotFound 参数未找到异常

func (*ArgNotFound) Error

func (e *ArgNotFound) Error() string

Error 返回错误字符串

type ArgsNotMatch

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

ArgsNotMatch 参数不匹配异常

func (*ArgsNotMatch) Error

func (i *ArgsNotMatch) Error() string

Error 返回错误字符串

type FieldNotFound

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

FieldNotFound 类型没有找到

func (*FieldNotFound) Error

func (t *FieldNotFound) Error() string

Error 返回错误字符串

type Frame added in v1.0.5

type Frame struct {
	// Func contains a function name.
	Func string
	// Line contains a line number.
	Line int
	// Path contains a file path.
	Path string
}

Frame is a single step in stack trace.

func StackTrace added in v1.0.5

func StackTrace(err error) []Frame

StackTrace returns stack trace of an error. It will be empty if err is not of type Error.

func (Frame) String added in v1.0.5

func (f Frame) String() string

String formats Frame to string.

type FuncNotFound

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

FuncNotFound 函数未找到异常

func (*FuncNotFound) Error

func (e *FuncNotFound) Error() string

Error 返回错误字符串

type IllegalParam

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

IllegalParam 参数错误异常

func (*IllegalParam) Cause

func (i *IllegalParam) Cause() error

Cause 获取错误的原因

func (*IllegalParam) Error

func (i *IllegalParam) Error() (s string)

Error 返回错误字符串

type IllegalParamType

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

IllegalParamType 参数类型错误异常

func (*IllegalParamType) Error

func (i *IllegalParamType) Error() string

Error 返回错误字符串

type IllegalStatus

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

IllegalStatus 状态错误异常

func (*IllegalStatus) Error

func (i *IllegalStatus) Error() string

Error 返回错误字符串

type RequiredBuildFlags added in v1.0.5

type RequiredBuildFlags struct {
	TraceableError
	// contains filtered or unexported fields
}

RequiredBuildFlags 编译标记未找到 典型的比如: -gcflags="all=-l", -ldflags="-s=false"

func NewRequiredBuildFlagsError added in v1.0.5

func NewRequiredBuildFlagsError(flags ...string) *RequiredBuildFlags

NewRequiredBuildFlagsError 创建编译标记未找到异常 flags 编译、链接标记

type ReturnParamNotFound

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

ReturnParamNotFound 返回值未找到异常

func (*ReturnParamNotFound) Error

func (e *ReturnParamNotFound) Error() string

Error 返回错误字符串

type ReturnsNotMatch

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

ReturnsNotMatch 返回参数不匹配异常

func (*ReturnsNotMatch) Error

func (i *ReturnsNotMatch) Error() string

Error 返回错误字符串

type Traceable

type Traceable interface {
	// Cause 获取错误的原因
	Cause() error
	// StackTrace 获取错误的堆栈信息
	StackTrace() []Frame
}

Traceable 带原因的异常类型 TODO later 可以使用go自带的 %w 功能替代?

type TraceableError

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

TraceableError 可跟踪的错误,异常转述包装

func (*TraceableError) Cause

func (w *TraceableError) Cause() error

Cause 获取错误的原因

func (*TraceableError) Error

func (w *TraceableError) Error() string

Error 错误描述

func (*TraceableError) StackTrace added in v1.0.5

func (w *TraceableError) StackTrace() []Frame

type TypeNotFound

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

TypeNotFound 类型没有找到

func (*TypeNotFound) Error

func (t *TypeNotFound) Error() string

Error 返回错误字符串

Jump to

Keyboard shortcuts

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