Sora Watermark Remover - Allows you to remove the watermark from Sora videos.Try Now

CurateClick

pkg.go.dev favicon

errors

一个Go语言的错误处理工具库,支持错误堆栈、错误码和错误链功能,简化错误处理流程并提升调试效率。

Check out errors on CurateClick

• Copy the embed code to showcase this product on your website

• Share on X to spread the word about this amazing tool

https://github.com/morrisxyang/errorsREADME# errorsGo ReferenceStatic BadgeCoverage StatusGo Report CardStatic Badge简单的支持错误堆栈, 错误码, 错误链的工具库:- 支持携带堆栈, 嵌套构造错误链- 支持携带错误码, 方便接口返回- 支持自定义堆栈打印深度和错误链打印格式- 使用 CallersFrames 替代 FuncForPC 生成堆栈, 避免特殊情况line number错误等问题, 详见runtime: strongly encourage using CallersFrames over FuncForPC with Callers result- 简化堆栈信息, 一条链路多次Wrap操作只保留最深层堆栈, 只打印一次## 安装和文档安装使用 go get github.com/morrisxyang/errors文档地址是 https://pkg.go.dev/github.com/morrisxyang/errors## 快速开始构造错误链gofunc a() error {err := b()err = Wrap(err, "a failed reason")return err}func b() error {err := c()err = Wrap(err, "b failed reason")return err}func c() error {_, err := os.Open("test")if err != nil {return WrapWithCode(err, 123, "c failed reason")}return nil}打印错误信息, %+v会打印堆栈, %v只打印错误信息goa failed reasonCaused by: b failed reasonCaused by: 123, c failed reasonCaused by: open test: no such file or directorygithub.com/morrisxyang/errors.c/Users/morrisyang/Nutstore Files/go-proj/githuberrors/errors_test.go:94github.com/morrisxyang/errors.b/Users/morrisyang/Nutstore Files/go-proj/githuberrors/errors_test.go:86github.com/morrisxyang/errors.a/Users/morrisyang/Nutstore Files/go-proj/githuberrors/errors_test.go:80....堆栈信息省略## 核心方法### 错误封装- func New(msg string) error- func Newf(format string, args ...interface{}) error- func NewWithCode(code int, msg string) error- func NewWithCodef(code int, format string, args ...interface{}) error- func Wrap(e error, msg string) error- func Wrapf(e error, format string, args ...interface{}) error- func WrapWithCode(e error, code int, msg string) error- func WrapWithCodef(e error, code int, format string, args ...interface{}) error### 错误解析- func Code(e error) int- func EffectiveCode(e error) int- func Msg(e error) string- func As(err error, target interface{}) bool- func Is(err, target error) bool- func Cause(e error) error- func Unwrap(err error) error### 配置- type Config- - func GetCfg() *Config- func ResetCfg()- func SetCfg(c *Config)## FAQ1. 多次 Wrap 错误会携带多次堆栈吗? 可在调用链路上多次Wrap, 添加说明信息, 但只有最深层的Wrap操作会设置堆栈, 继续 Wrap, return err 等操作不会影响堆栈信息2. 在链路中某个错误设置了合适的错误码, 然后继续Wrap时没有设置, 如何获取? 建议在合适的清晰的时机设置有效的错误码, 可以使用EffectiveCode获取链路中外层第一个有效的非0错误码, 由于系统调用等情况, 同一链路中可能有多个错误携带错误码, 此时默认外层的错误码应该对外暴露, 屏蔽了内层的详细信息.

Latest Weekly Picks

nanobananaimg.com favicon
Weekly Pick

Nano Banana AI Image Generator for Professional Image Creation with Nano Banana Pro Models

Nano Banana
pslscale.com favicon
Weekly Pick

使用 Gemini 3 Pro 分析八字命理

人生 K 线
seedance15.ai favicon
Weekly Pick

Create Cinematic AI Videos from Text or Images with Seedance 1.5

Seedance 1.5 AI
tatted.ai favicon
Weekly Pick

The Tatted AI Tattoo Generator is a tool that allows you to create beautiful custom tattoos within seconds.

Tatted
pslscale.com favicon
Weekly Pick

Discover your PSL (Perceived Sexual Market Value) score with our AI-powered facial analysis

PSL Scale

IPYNB to PDF Converter – Free & Secure

www.reverie.im favicon
Weekly Pick

Dream It, Chat It, Create It

Reverie
make.ink favicon
Weekly Pick

Your AI tattoo generator for pro-grade concepts

make ink