Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Wrap errors with no kind #13

Open
erizocosmico opened this issue Aug 2, 2019 · 0 comments
Open

[Proposal] Wrap errors with no kind #13

erizocosmico opened this issue Aug 2, 2019 · 0 comments

Comments

@erizocosmico
Copy link
Contributor

Sometimes as we pass the error down the line we might want to annotate the error with more information and we don't want to check its type later. For these cases, Kind is an overkill, because you need to declare a kind and then use Wrap.

A Wrap top-level function could be nice for this use-case.

if err != nil {
    return nil, errors.Wrap(err, "couldn't get value at position %d", position)
}

Instead of:

var errCantGetValueAtPos = errors.NewKind("couldn't get value at position %d")

if err != nil {
    return nil, errCantGetValueAtPos.Wrap(err, position)
}

It enables having ad-hoc error messages just for adding info and reduces the amount of kinds that need to be declared.

Reference:

  • xerrors.Errorf in the new experimental errors package that is probably going into Go 1.13.
@erizocosmico erizocosmico changed the title Wrap errors with no kind [Proposal] Wrap errors with no kind Aug 2, 2019
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

No branches or pull requests

1 participant