From 082a8bd8920dfa1889e3e216a7e5a0e62f0f677b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 9 May 2020 21:25:30 +0200 Subject: [PATCH 1/2] vendor: pkg/errors v0.9.1 full diff: https://github.com/pkg/errors/compare/v0.8.1...v0.9.1 Signed-off-by: Sebastiaan van Stijn --- vendor.conf | 2 +- vendor/github.com/pkg/errors/README.md | 11 ++++- vendor/github.com/pkg/errors/errors.go | 8 +++- vendor/github.com/pkg/errors/go113.go | 38 +++++++++++++++++ vendor/github.com/pkg/errors/stack.go | 58 +++++++++++++++++++------- 5 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 vendor/github.com/pkg/errors/go113.go diff --git a/vendor.conf b/vendor.conf index a45dbf70adb0..d54968c4ff52 100755 --- a/vendor.conf +++ b/vendor.conf @@ -55,7 +55,7 @@ github.com/opencontainers/go-digest 279bed98673dd5bef374d3b6e4b0 github.com/opencontainers/image-spec d60099175f88c47cd379c4738d158884749ed235 # v1.0.1 github.com/opencontainers/runc dc9208a3303feef5b3839f4323d9beb36df0a9dd # v1.0.0-rc10 github.com/opentracing/opentracing-go 1361b9cd60be79c4c3a7fa9841b3c132e40066a7 -github.com/pkg/errors ba968bfe8b2f7e042a574c888954fccecfa385b4 # v0.8.1 +github.com/pkg/errors 614d223910a179a466c1767a985424175c39b465 # v0.9.1 github.com/prometheus/client_golang c5b7fccd204277076155f10851dad72b76a49317 # v0.8.0 github.com/prometheus/client_model 6f3806018612930941127f2a7c6c453ba2c527d2 github.com/prometheus/common 7600349dcfe1abd18d72d3a1770870d9800a7801 diff --git a/vendor/github.com/pkg/errors/README.md b/vendor/github.com/pkg/errors/README.md index 6483ba2afb51..54dfdcb12ea1 100644 --- a/vendor/github.com/pkg/errors/README.md +++ b/vendor/github.com/pkg/errors/README.md @@ -41,11 +41,18 @@ default: [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors). +## Roadmap + +With the upcoming [Go2 error proposals](https://go.googlesource.com/proposal/+/master/design/go2draft.md) this package is moving into maintenance mode. The roadmap for a 1.0 release is as follows: + +- 0.9. Remove pre Go 1.9 and Go 1.10 support, address outstanding pull requests (if possible) +- 1.0. Final release. + ## Contributing -We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high. +Because of the Go2 errors changes, this package is not accepting proposals for new functionality. With that said, we welcome pull requests, bug fixes and issue reports. -Before proposing a change, please discuss your change by raising an issue. +Before sending a PR, please discuss your change by raising an issue. ## License diff --git a/vendor/github.com/pkg/errors/errors.go b/vendor/github.com/pkg/errors/errors.go index 7421f326ffe8..161aea258296 100644 --- a/vendor/github.com/pkg/errors/errors.go +++ b/vendor/github.com/pkg/errors/errors.go @@ -82,7 +82,7 @@ // // if err, ok := err.(stackTracer); ok { // for _, f := range err.StackTrace() { -// fmt.Printf("%+s:%d", f) +// fmt.Printf("%+s:%d\n", f, f) // } // } // @@ -159,6 +159,9 @@ type withStack struct { func (w *withStack) Cause() error { return w.error } +// Unwrap provides compatibility for Go 1.13 error chains. +func (w *withStack) Unwrap() error { return w.error } + func (w *withStack) Format(s fmt.State, verb rune) { switch verb { case 'v': @@ -241,6 +244,9 @@ type withMessage struct { func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() } func (w *withMessage) Cause() error { return w.cause } +// Unwrap provides compatibility for Go 1.13 error chains. +func (w *withMessage) Unwrap() error { return w.cause } + func (w *withMessage) Format(s fmt.State, verb rune) { switch verb { case 'v': diff --git a/vendor/github.com/pkg/errors/go113.go b/vendor/github.com/pkg/errors/go113.go new file mode 100644 index 000000000000..be0d10d0c793 --- /dev/null +++ b/vendor/github.com/pkg/errors/go113.go @@ -0,0 +1,38 @@ +// +build go1.13 + +package errors + +import ( + stderrors "errors" +) + +// Is reports whether any error in err's chain matches target. +// +// The chain consists of err itself followed by the sequence of errors obtained by +// repeatedly calling Unwrap. +// +// 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 stderrors.Is(err, target) } + +// As finds the first error in err's chain that matches target, and if so, sets +// target to that error value and returns true. +// +// The chain consists of err itself followed by the sequence of errors obtained by +// repeatedly calling Unwrap. +// +// An error matches target if the error's concrete value is assignable to the value +// pointed to by target, or if the error has a method As(interface{}) bool such that +// As(target) returns true. In the latter case, the As method is responsible for +// setting target. +// +// As will panic if target is not a non-nil pointer to either a type that implements +// error, or to any interface type. As returns false if err is nil. +func As(err error, target interface{}) bool { return stderrors.As(err, target) } + +// Unwrap returns the result of calling the Unwrap method on err, if err's +// type contains an Unwrap method returning error. +// Otherwise, Unwrap returns nil. +func Unwrap(err error) error { + return stderrors.Unwrap(err) +} diff --git a/vendor/github.com/pkg/errors/stack.go b/vendor/github.com/pkg/errors/stack.go index 2874a048cf3e..779a8348fb9c 100644 --- a/vendor/github.com/pkg/errors/stack.go +++ b/vendor/github.com/pkg/errors/stack.go @@ -5,10 +5,13 @@ import ( "io" "path" "runtime" + "strconv" "strings" ) // Frame represents a program counter inside a stack frame. +// For historical reasons if Frame is interpreted as a uintptr +// its value represents the program counter + 1. type Frame uintptr // pc returns the program counter for this frame; @@ -37,6 +40,15 @@ func (f Frame) line() int { return line } +// name returns the name of this function, if known. +func (f Frame) name() string { + fn := runtime.FuncForPC(f.pc()) + if fn == nil { + return "unknown" + } + return fn.Name() +} + // Format formats the frame according to the fmt.Formatter interface. // // %s source file @@ -54,22 +66,16 @@ func (f Frame) Format(s fmt.State, verb rune) { case 's': switch { case s.Flag('+'): - pc := f.pc() - fn := runtime.FuncForPC(pc) - if fn == nil { - io.WriteString(s, "unknown") - } else { - file, _ := fn.FileLine(pc) - fmt.Fprintf(s, "%s\n\t%s", fn.Name(), file) - } + io.WriteString(s, f.name()) + io.WriteString(s, "\n\t") + io.WriteString(s, f.file()) default: io.WriteString(s, path.Base(f.file())) } case 'd': - fmt.Fprintf(s, "%d", f.line()) + io.WriteString(s, strconv.Itoa(f.line())) case 'n': - name := runtime.FuncForPC(f.pc()).Name() - io.WriteString(s, funcname(name)) + io.WriteString(s, funcname(f.name())) case 'v': f.Format(s, 's') io.WriteString(s, ":") @@ -77,6 +83,16 @@ func (f Frame) Format(s fmt.State, verb rune) { } } +// MarshalText formats a stacktrace Frame as a text string. The output is the +// same as that of fmt.Sprintf("%+v", f), but without newlines or tabs. +func (f Frame) MarshalText() ([]byte, error) { + name := f.name() + if name == "unknown" { + return []byte(name), nil + } + return []byte(fmt.Sprintf("%s %s:%d", name, f.file(), f.line())), nil +} + // StackTrace is stack of Frames from innermost (newest) to outermost (oldest). type StackTrace []Frame @@ -94,16 +110,30 @@ func (st StackTrace) Format(s fmt.State, verb rune) { switch { case s.Flag('+'): for _, f := range st { - fmt.Fprintf(s, "\n%+v", f) + io.WriteString(s, "\n") + f.Format(s, verb) } case s.Flag('#'): fmt.Fprintf(s, "%#v", []Frame(st)) default: - fmt.Fprintf(s, "%v", []Frame(st)) + st.formatSlice(s, verb) } case 's': - fmt.Fprintf(s, "%s", []Frame(st)) + st.formatSlice(s, verb) + } +} + +// formatSlice will format this StackTrace into the given buffer as a slice of +// Frame, only valid when called with '%s' or '%v'. +func (st StackTrace) formatSlice(s fmt.State, verb rune) { + io.WriteString(s, "[") + for i, f := range st { + if i > 0 { + io.WriteString(s, " ") + } + f.Format(s, verb) } + io.WriteString(s, "]") } // stack represents a stack of program counters. From bb7ef2cb3afba7787388cc9d65017b8135393ec8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 9 May 2020 21:28:48 +0200 Subject: [PATCH 2/2] Update some uses of errors.Cause() to errors.Is() Signed-off-by: Sebastiaan van Stijn --- cli-plugins/manager/error.go | 5 +++++ cli-plugins/manager/error_test.go | 2 +- cli/config/config_test.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli-plugins/manager/error.go b/cli-plugins/manager/error.go index 1ad28678695a..11822d660c0f 100644 --- a/cli-plugins/manager/error.go +++ b/cli-plugins/manager/error.go @@ -25,6 +25,11 @@ func (e *pluginError) Cause() error { return e.cause } +// Unwrap provides compatibility for Go 1.13 error chains. +func (e *pluginError) Unwrap() error { + return e.cause +} + // MarshalText marshalls the pluginError into a textual form. func (e *pluginError) MarshalText() (text []byte, err error) { return []byte(e.cause.Error()), nil diff --git a/cli-plugins/manager/error_test.go b/cli-plugins/manager/error_test.go index bc318251babb..fbdb57fd4d53 100644 --- a/cli-plugins/manager/error_test.go +++ b/cli-plugins/manager/error_test.go @@ -16,7 +16,7 @@ func TestPluginError(t *testing.T) { inner := fmt.Errorf("testing") err = wrapAsPluginError(inner, "wrapping") assert.Error(t, err, "wrapping: testing") - assert.Equal(t, inner, errors.Cause(err)) + assert.Assert(t, errors.Is(err, inner)) actual, err := yaml.Marshal(err) assert.NilError(t, err) diff --git a/cli/config/config_test.go b/cli/config/config_test.go index d0fccacf8d6a..f5580223425b 100644 --- a/cli/config/config_test.go +++ b/cli/config/config_test.go @@ -89,7 +89,7 @@ func TestEmptyFile(t *testing.T) { assert.NilError(t, err) _, err = Load(tmpHome) - assert.Equal(t, errors.Cause(err), io.EOF) + assert.Assert(t, errors.Is(err, io.EOF)) assert.ErrorContains(t, err, ConfigFileName) }