We're often giving a lot of context to context.Context, but when an error is returned, most of the case the whole context is lost when an error is returned, we have the stack trace, but not the ID of the models which are concerned.
I'm proposing to add overlay type keeping the context.
errors.CtxWrap(ctx, err, "string") error
errors.CtxWrapf(ctx, err, "format", args...) error
errors.Ctx(err) context.Context
errors.Cause(err) error
The goal is for instance the ability for go-handlers middleware to do something like this.
log := logger.Get(errors.Ctx(err))
log.WithError(errors.Cause(err)).Error("error during request")
What do you think of this?