Skip to content

Commit e74624b

Browse files
committed
all: drop golang.org/x/xerrors
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í <mvdan@mvdan.cc> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536094 Reviewed-by: Roger Peppe <rogpeppe@gmail.com> Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
1 parent 935a926 commit e74624b

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

cue/ast/ident.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,5 @@ func LabelName(l Label) (name string, isIdent bool, err error) {
191191
}
192192

193193
// ErrIsExpression reports whether a label is an expression.
194-
// This error is never returned directly. Use errors.Is or xerrors.Is.
194+
// This error is never returned directly. Use errors.Is.
195195
var ErrIsExpression = errors.New("not a concrete label")

cue/errors/errors.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"strings"
3030

3131
"github.com/mpvl/unique"
32-
"golang.org/x/xerrors"
3332

3433
"cuelang.org/go/cue/token"
3534
)
@@ -43,15 +42,15 @@ func New(msg string) error {
4342
// Unwrap returns the result of calling the Unwrap method on err, if err
4443
// implements Unwrap. Otherwise, Unwrap returns nil.
4544
func Unwrap(err error) error {
46-
return xerrors.Unwrap(err)
45+
return errors.Unwrap(err)
4746
}
4847

4948
// Is reports whether any error in err's chain matches target.
5049
//
5150
// An error is considered to match a target if it is equal to that target or if
5251
// it implements a method Is(error) bool such that Is(target) returns true.
5352
func Is(err, target error) bool {
54-
return xerrors.Is(err, target)
53+
return errors.Is(err, target)
5554
}
5655

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

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

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

154153
// Path returns the path of an Error if err is of that type.
155154
func Path(err error) []string {
156-
if e := Error(nil); xerrors.As(err, &e) {
155+
if e := Error(nil); errors.As(err, &e) {
157156
return e.Path()
158157
}
159158
return nil
@@ -326,7 +325,7 @@ type list []Error
326325

327326
func (p list) Is(err, target error) bool {
328327
for _, e := range p {
329-
if xerrors.Is(e, target) {
328+
if errors.Is(e, target) {
330329
return true
331330
}
332331
}
@@ -335,7 +334,7 @@ func (p list) Is(err, target error) bool {
335334

336335
func (p list) As(err error, target interface{}) bool {
337336
for _, e := range p {
338-
if xerrors.As(e, target) {
337+
if errors.As(e, target) {
339338
return true
340339
}
341340
}
@@ -567,7 +566,7 @@ func writeErr(w io.Writer, err Error) {
567566
}
568567

569568
for {
570-
u := xerrors.Unwrap(err)
569+
u := errors.Unwrap(err)
571570

572571
printed := false
573572
msg, args := err.Msg()

encoding/protobuf/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
package protobuf
1616

1717
import (
18+
"fmt"
1819
"strings"
1920
"text/scanner"
2021

2122
"github.com/emicklei/proto"
22-
"golang.org/x/xerrors"
2323

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

3434
func fail(pos scanner.Position, err error) {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ require (
2020
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
2121
golang.org/x/text v0.3.7
2222
golang.org/x/tools v0.0.0-20200612220849-54c614fe050c
23-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
2423
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
2524
)
2625

@@ -35,5 +34,6 @@ require (
3534
github.com/pkg/errors v0.8.1 // indirect
3635
github.com/pmezard/go-difflib v1.0.0 // indirect
3736
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449 // indirect
37+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
3838
gopkg.in/errgo.v2 v2.1.0 // indirect
3939
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
4040
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4141
github.com/protocolbuffers/txtpbfmt v0.0.0-20201118171849-f6a6b3f636fc h1:gSVONBi2HWMFXCa9jFdYvYk7IwW/mTLxWOF7rXS4LO0=
4242
github.com/protocolbuffers/txtpbfmt v0.0.0-20201118171849-f6a6b3f636fc/go.mod h1:KbKfKPy2I6ecOIGA9apfheFv14+P3RSmmQvshofQyMY=
43-
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
44-
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
4543
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
4644
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
4745
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

0 commit comments

Comments
 (0)