Skip to content

Commit

Permalink
all: drop golang.org/x/xerrors
Browse files Browse the repository at this point in the history
The error value wrapping APIs in the standard library's errors package
have been available since Go 1.13, released nearly three years ago.
We now require at least Go 1.16, so we can simplify our code.

Change-Id: I25fb1eede98aece84ad93b19d0542089ffadfe0b
Signed-off-by: Daniel Martí <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536094
Reviewed-by: Roger Peppe <[email protected]>
Reviewed-by: Marcel van Lohuizen <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mvdan committed Apr 12, 2022
1 parent 935a926 commit e74624b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cue/ast/ident.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,5 @@ func LabelName(l Label) (name string, isIdent bool, err error) {
}

// ErrIsExpression reports whether a label is an expression.
// This error is never returned directly. Use errors.Is or xerrors.Is.
// This error is never returned directly. Use errors.Is.
var ErrIsExpression = errors.New("not a concrete label")
17 changes: 8 additions & 9 deletions cue/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"strings"

"github.com/mpvl/unique"
"golang.org/x/xerrors"

"cuelang.org/go/cue/token"
)
Expand All @@ -43,15 +42,15 @@ func New(msg string) error {
// Unwrap returns the result of calling the Unwrap method on err, if err
// implements Unwrap. Otherwise, Unwrap returns nil.
func Unwrap(err error) error {
return xerrors.Unwrap(err)
return errors.Unwrap(err)
}

// Is reports whether any error in err's chain matches target.
//
// An error is considered to match a target if it is equal to that target or if
// it implements a method Is(error) bool such that Is(target) returns true.
func Is(err, target error) bool {
return xerrors.Is(err, target)
return errors.Is(err, target)
}

// As finds the first error in err's chain that matches the type to which target
Expand All @@ -64,7 +63,7 @@ func Is(err, target error) bool {
// The As method should set the target to its value and return true if err
// matches the type to which target points.
func As(err error, target interface{}) bool {
return xerrors.As(err, target)
return errors.As(err, target)
}

// A Message implements the error interface as well as Message to allow
Expand Down Expand Up @@ -119,7 +118,7 @@ type Error interface {
// by relevance when possible and with duplicates removed.
func Positions(err error) []token.Pos {
e := Error(nil)
if !xerrors.As(err, &e) {
if !errors.As(err, &e) {
return nil
}

Expand Down Expand Up @@ -153,7 +152,7 @@ func (s byPos) Less(i, j int) bool { return comparePos(s[i], s[j]) == -1 }

// Path returns the path of an Error if err is of that type.
func Path(err error) []string {
if e := Error(nil); xerrors.As(err, &e) {
if e := Error(nil); errors.As(err, &e) {
return e.Path()
}
return nil
Expand Down Expand Up @@ -326,7 +325,7 @@ type list []Error

func (p list) Is(err, target error) bool {
for _, e := range p {
if xerrors.Is(e, target) {
if errors.Is(e, target) {
return true
}
}
Expand All @@ -335,7 +334,7 @@ func (p list) Is(err, target error) bool {

func (p list) As(err error, target interface{}) bool {
for _, e := range p {
if xerrors.As(e, target) {
if errors.As(e, target) {
return true
}
}
Expand Down Expand Up @@ -567,7 +566,7 @@ func writeErr(w io.Writer, err Error) {
}

for {
u := xerrors.Unwrap(err)
u := errors.Unwrap(err)

printed := false
msg, args := err.Msg()
Expand Down
4 changes: 2 additions & 2 deletions encoding/protobuf/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package protobuf

import (
"fmt"
"strings"
"text/scanner"

"github.com/emicklei/proto"
"golang.org/x/xerrors"

"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/token"
Expand All @@ -28,7 +28,7 @@ import (
// failf panics with a marked error that can be intercepted upon returning
// from parsing.
func failf(pos scanner.Position, format string, args ...interface{}) {
panic(protoError{pos, xerrors.Errorf(format, args...)})
panic(protoError{pos, fmt.Errorf(format, args...)})
}

func fail(pos scanner.Position, err error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
golang.org/x/text v0.3.7
golang.org/x/tools v0.0.0-20200612220849-54c614fe050c
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

Expand All @@ -35,5 +34,6 @@ require (
github.com/pkg/errors v0.8.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/errgo.v2 v2.1.0 // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/protocolbuffers/txtpbfmt v0.0.0-20201118171849-f6a6b3f636fc h1:gSVONBi2HWMFXCa9jFdYvYk7IwW/mTLxWOF7rXS4LO0=
github.com/protocolbuffers/txtpbfmt v0.0.0-20201118171849-f6a6b3f636fc/go.mod h1:KbKfKPy2I6ecOIGA9apfheFv14+P3RSmmQvshofQyMY=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down

0 comments on commit e74624b

Please sign in to comment.