Skip to content

[errors] Proposal: overlay over pkg/errors to keep context in the error #88

@Soulou

Description

@Soulou

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions