1
0
Fork
You've already forked werr
0
No description
  • Go 100%
Find a file
2025年04月19日 20:16:22 +02:00
test doc typo (thanks Tigraff) 2023年07月01日 15:50:28 +02:00
.hgignore rejoint git 2019年11月29日 19:29:57 +01:00
changelog.md v0.6.0 only method(line) 2025年04月19日 20:16:22 +02:00
go.mod v0.5.0 opt-in trace 2023年06月25日 21:11:22 +02:00
go.sum calcul correct espaces, et tidy mod 2020年01月08日 18:33:55 +01:00
LICENSE v0.5.0 opt-in trace 2023年06月25日 21:11:22 +02:00
README.md v0.6.0 only method(line) 2025年04月19日 20:16:22 +02:00
trace.go v0.6.0 only method(line) 2025年04月19日 20:16:22 +02:00

Disclaimer: private use and with my coworkers. It will break! feel free to copy-paste.

werr: opt-in traces in errors.

Add the name of the function/method and the file:line opt-in on each error to print a minimalist traceback with decorations.

Example:

> gotodo/vue.Issue() issue.go:29
read issue:
> gotodo/model.(*Project).GetIssueStr() issue.go:99
Erreur en lecture issue x: strconv.Atoi: parsing "x": invalid syntax

Usage

go get go.flibuste.net/werr

Wrap or create the error with one of the werr functions, it'll add the function/method name and the file:line in the string. Nothing more.

Wrap and Wrapf will wrap the error, like %w. Errorf is like fmt.Errorf with trace New is like errors.New with trace

Just print the error.

How to adapt a legacy app

Replace fmt.Errorf with werr.Errorf

sed -i 's/fmt.Errorf/werr.Errorf/g' *go

Replace errors.New with werr.New

sed -i 's/errors.New/werr.New/g' *go

Add trace + wrap to return err without decoration, like %w

sed -i 's/return err/return werr.Wrap(err)/g' *go

Add import go.flibuste.net/werr

goimports -w *.go

Find return err still not decorated ack 'return.*err$'

Be carefull when comparing err == ... to replace by errors.Is Also err.(...