Adding context to errors in Go
· 4 min read
This post compares two ways to enrich Go errors — both sentinel and typed — with additional context:
github.com/ygrebnov/errorc.With- the standard
fmt.Errorfapproach
The main difference is not only syntax. errorc gives you a more structured way to attach fields, and it works especially well together with github.com/ygrebnov/keys when you want stable hierarchical field names such as user.id or request.trace_id.
