Open utterances-bot opened 3 years ago
This is a great article, but I'm struggling to figure out how to construct an cockroachdb/errors error with a map of key values.
Any thoughts on this?
I realized we already talked in a github issue, and you previously advised:
For now our recommended best practice is to annotate your fields into your context.Context using the logtags package at https://github.com/cockroachdb/logtags. This gives you some kind of permanent access to your key/value pairs throughout your call stack, which you can also use in logging (besides error handling) when constructing an error, do
errors.WithContextTags(errors.New("woo"), ctx)
to attach the current k/v pairs from the context into the error.
Beyond fmt.Errorf()—everyday error objects in Go - The CockroachDB errors library, part 4/ · dr knz @ work
The idiomatic way to propagate errors in Go is using the predefined type error. Yet Go’s standard library only provides very rudimentary constructors for error objects, errors.New() and fmt.Errorf(). This article introduces how the CockroachDB errors library, a drop-in replacement to Go’s own errors package, expands …
https://dr-knz.net/cockroachdb-errors-everyday.html