Skip to content

Drop github.com/pkg/errors and use Golang errors package from standard library#219

Merged
jbkempf merged 4 commits into
videolabs:masterfrom
elboulangero:github/pkg-errors
May 19, 2026
Merged

Drop github.com/pkg/errors and use Golang errors package from standard library#219
jbkempf merged 4 commits into
videolabs:masterfrom
elboulangero:github/pkg-errors

Conversation

@elboulangero

Copy link
Copy Markdown
Contributor

github.com/pkg/errors is mostly obsolete, and the last relevant commit was in 2020: https://github.com/pkg/errors/commits/master/

In the meantime, Golang's errors package got better, and now that we raised the baseline to Go 1,18, it is a suitable replacement.

It just lacks errors.WithStack(), but I think we can just stop using it.

This is in preparation to switch away from "github.com/pkg/errors"
(unmaintained), and replace it with Golang "errors" package.

errors.WithStack() is specific to github.com/pkg/errors, and there's no
equivalent in the Golang errors package. So the easiest thing we can do
is to just stop using it.

errors.WithStack() is mainly used in the database migration code, in
order to have an abundance of logs in case something goes wrong. It's
nice-to-have but not mandatory.

Note that, in database/redis.go, we now print the error from Upgrade()
with "%v" instead of "%+v": the purpose of "%+v" was to print the
annotations added with errors.WithStack(), so it's no longer useful.

errors.WithStack() is also used to log a GeoIPError: this error is a
struct with a slice of errors (there can be a maximum of 2 errors, given
that we load 2 databases). So the idea was to print these 2 errors
thanks to errors.WithStack(). However that works only if you print the
error with "%+v", which was not done, so I don't think it ever worked as
intended.  Again, nice-to-have but not mandatory, we can live without.
This is in preparation to switch away from "github.com/pkg/errors"
(unmaintained), and replace it with Golang "errors" package.

fmt.Errorf() was introduced in Go 1.13, making errors.Wrap() redundant,
cf. https://tip.golang.org/doc/go1.13#error_wrapping.
At this point github.com/pkg/errors is no longer used so we can remove
it.
This change improves readability IMO.

errors.As was introduced in Go 1.13, and here are some references for
the avid reader:
* https://tip.golang.org/doc/go1.13#error_wrapping
* https://go.dev/blog/go1.13-errors#examining-errors-with-is-and-as
* https://pkg.go.dev/errors#As
@jbkempf jbkempf merged commit 1130186 into videolabs:master May 19, 2026
3 checks passed
@elboulangero elboulangero deleted the github/pkg-errors branch May 20, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants