Skip to content

[Proposal] Wrap errors with no kind #13

Open
@erizocosmico

Description

@erizocosmico

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.

Metadata

Metadata

Assignees

No one assigned

    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