From e74624bef18ffdce676d250bb0fbeca8575a4cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 9 Apr 2022 11:23:18 +0900 Subject: [PATCH] all: drop golang.org/x/xerrors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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í Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536094 Reviewed-by: Roger Peppe Reviewed-by: Marcel van Lohuizen TryBot-Result: CUEcueckoo Unity-Result: CUEcueckoo --- cue/ast/ident.go | 2 +- cue/errors/errors.go | 17 ++++++++--------- encoding/protobuf/util.go | 4 ++-- go.mod | 2 +- go.sum | 2 -- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/cue/ast/ident.go b/cue/ast/ident.go index 4584a6860a2..1f400b28699 100644 --- a/cue/ast/ident.go +++ b/cue/ast/ident.go @@ -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") diff --git a/cue/errors/errors.go b/cue/errors/errors.go index 476d586c404..af5038c22bc 100644 --- a/cue/errors/errors.go +++ b/cue/errors/errors.go @@ -29,7 +29,6 @@ import ( "strings" "github.com/mpvl/unique" - "golang.org/x/xerrors" "cuelang.org/go/cue/token" ) @@ -43,7 +42,7 @@ 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. @@ -51,7 +50,7 @@ func Unwrap(err error) error { // 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 @@ -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 @@ -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 } @@ -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 @@ -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 } } @@ -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 } } @@ -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() diff --git a/encoding/protobuf/util.go b/encoding/protobuf/util.go index ad6328556f0..1fc17f61b5b 100644 --- a/encoding/protobuf/util.go +++ b/encoding/protobuf/util.go @@ -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" @@ -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) { diff --git a/go.mod b/go.mod index 029c75478ed..20d438c1ffc 100644 --- a/go.mod +++ b/go.mod @@ -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 ) @@ -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 ) diff --git a/go.sum b/go.sum index f6a89d75e0d..4f9357bc36a 100644 --- a/go.sum +++ b/go.sum @@ -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=