aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/pkg
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2017-12-13 10:43:58 -0800
committerChristine Dodrill <me@christine.website>2017-12-13 10:43:58 -0800
commit91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8 (patch)
tree39b7911168d9ffc501894b79842975735bde6c81 /vendor/github.com/pkg
parent141a3320ff790cbaa52319371de530ae9fd09d89 (diff)
downloadxesite-91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8.tar.xz
xesite-91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8.zip
convert to go buildpack
Diffstat (limited to 'vendor/github.com/pkg')
-rw-r--r--vendor/github.com/pkg/errors/.gitignore24
-rw-r--r--vendor/github.com/pkg/errors/.travis.yml11
-rw-r--r--vendor/github.com/pkg/errors/LICENSE23
-rw-r--r--vendor/github.com/pkg/errors/README.md52
-rw-r--r--vendor/github.com/pkg/errors/appveyor.yml32
-rw-r--r--vendor/github.com/pkg/errors/bench_test.go59
-rw-r--r--vendor/github.com/pkg/errors/errors_test.go226
-rw-r--r--vendor/github.com/pkg/errors/example_test.go205
-rw-r--r--vendor/github.com/pkg/errors/format_test.go535
-rw-r--r--vendor/github.com/pkg/errors/stack_test.go292
10 files changed, 1459 insertions, 0 deletions
diff --git a/vendor/github.com/pkg/errors/.gitignore b/vendor/github.com/pkg/errors/.gitignore
new file mode 100644
index 0000000..daf913b
--- /dev/null
+++ b/vendor/github.com/pkg/errors/.gitignore
@@ -0,0 +1,24 @@
+# Compiled Object files, Static and Dynamic libs (Shared Objects)
+*.o
+*.a
+*.so
+
+# Folders
+_obj
+_test
+
+# Architecture specific extensions/prefixes
+*.[568vq]
+[568vq].out
+
+*.cgo1.go
+*.cgo2.c
+_cgo_defun.c
+_cgo_gotypes.go
+_cgo_export.*
+
+_testmain.go
+
+*.exe
+*.test
+*.prof
diff --git a/vendor/github.com/pkg/errors/.travis.yml b/vendor/github.com/pkg/errors/.travis.yml
new file mode 100644
index 0000000..588ceca
--- /dev/null
+++ b/vendor/github.com/pkg/errors/.travis.yml
@@ -0,0 +1,11 @@
+language: go
+go_import_path: github.com/pkg/errors
+go:
+ - 1.4.3
+ - 1.5.4
+ - 1.6.2
+ - 1.7.1
+ - tip
+
+script:
+ - go test -v ./...
diff --git a/vendor/github.com/pkg/errors/LICENSE b/vendor/github.com/pkg/errors/LICENSE
new file mode 100644
index 0000000..835ba3e
--- /dev/null
+++ b/vendor/github.com/pkg/errors/LICENSE
@@ -0,0 +1,23 @@
+Copyright (c) 2015, Dave Cheney <dave@cheney.net>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/pkg/errors/README.md b/vendor/github.com/pkg/errors/README.md
new file mode 100644
index 0000000..273db3c
--- /dev/null
+++ b/vendor/github.com/pkg/errors/README.md
@@ -0,0 +1,52 @@
+# errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors)
+
+Package errors provides simple error handling primitives.
+
+`go get github.com/pkg/errors`
+
+The traditional error handling idiom in Go is roughly akin to
+```go
+if err != nil {
+ return err
+}
+```
+which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error.
+
+## Adding context to an error
+
+The errors.Wrap function returns a new error that adds context to the original error. For example
+```go
+_, err := ioutil.ReadAll(r)
+if err != nil {
+ return errors.Wrap(err, "read failed")
+}
+```
+## Retrieving the cause of an error
+
+Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`.
+```go
+type causer interface {
+ Cause() error
+}
+```
+`errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example:
+```go
+switch err := errors.Cause(err).(type) {
+case *MyError:
+ // handle specifically
+default:
+ // unknown error
+}
+```
+
+[Read the package documentation for more information](https://godoc.org/github.com/pkg/errors).
+
+## 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.
+
+Before proposing a change, please discuss your change by raising an issue.
+
+## Licence
+
+BSD-2-Clause
diff --git a/vendor/github.com/pkg/errors/appveyor.yml b/vendor/github.com/pkg/errors/appveyor.yml
new file mode 100644
index 0000000..a932ead
--- /dev/null
+++ b/vendor/github.com/pkg/errors/appveyor.yml
@@ -0,0 +1,32 @@
+version: build-{build}.{branch}
+
+clone_folder: C:\gopath\src\github.com\pkg\errors
+shallow_clone: true # for startup speed
+
+environment:
+ GOPATH: C:\gopath
+
+platform:
+ - x64
+
+# http://www.appveyor.com/docs/installed-software
+install:
+ # some helpful output for debugging builds
+ - go version
+ - go env
+ # pre-installed MinGW at C:\MinGW is 32bit only
+ # but MSYS2 at C:\msys64 has mingw64
+ - set PATH=C:\msys64\mingw64\bin;%PATH%
+ - gcc --version
+ - g++ --version
+
+build_script:
+ - go install -v ./...
+
+test_script:
+ - set PATH=C:\gopath\bin;%PATH%
+ - go test -v ./...
+
+#artifacts:
+# - path: '%GOPATH%\bin\*.exe'
+deploy: off
diff --git a/vendor/github.com/pkg/errors/bench_test.go b/vendor/github.com/pkg/errors/bench_test.go
new file mode 100644
index 0000000..0416a3c
--- /dev/null
+++ b/vendor/github.com/pkg/errors/bench_test.go
@@ -0,0 +1,59 @@
+// +build go1.7
+
+package errors
+
+import (
+ "fmt"
+ "testing"
+
+ stderrors "errors"
+)
+
+func noErrors(at, depth int) error {
+ if at >= depth {
+ return stderrors.New("no error")
+ }
+ return noErrors(at+1, depth)
+}
+func yesErrors(at, depth int) error {
+ if at >= depth {
+ return New("ye error")
+ }
+ return yesErrors(at+1, depth)
+}
+
+func BenchmarkErrors(b *testing.B) {
+ var toperr error
+ type run struct {
+ stack int
+ std bool
+ }
+ runs := []run{
+ {10, false},
+ {10, true},
+ {100, false},
+ {100, true},
+ {1000, false},
+ {1000, true},
+ }
+ for _, r := range runs {
+ part := "pkg/errors"
+ if r.std {
+ part = "errors"
+ }
+ name := fmt.Sprintf("%s-stack-%d", part, r.stack)
+ b.Run(name, func(b *testing.B) {
+ var err error
+ f := yesErrors
+ if r.std {
+ f = noErrors
+ }
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ err = f(0, r.stack)
+ }
+ b.StopTimer()
+ toperr = err
+ })
+ }
+}
diff --git a/vendor/github.com/pkg/errors/errors_test.go b/vendor/github.com/pkg/errors/errors_test.go
new file mode 100644
index 0000000..1d8c635
--- /dev/null
+++ b/vendor/github.com/pkg/errors/errors_test.go
@@ -0,0 +1,226 @@
+package errors
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "reflect"
+ "testing"
+)
+
+func TestNew(t *testing.T) {
+ tests := []struct {
+ err string
+ want error
+ }{
+ {"", fmt.Errorf("")},
+ {"foo", fmt.Errorf("foo")},
+ {"foo", New("foo")},
+ {"string with format specifiers: %v", errors.New("string with format specifiers: %v")},
+ }
+
+ for _, tt := range tests {
+ got := New(tt.err)
+ if got.Error() != tt.want.Error() {
+ t.Errorf("New.Error(): got: %q, want %q", got, tt.want)
+ }
+ }
+}
+
+func TestWrapNil(t *testing.T) {
+ got := Wrap(nil, "no error")
+ if got != nil {
+ t.Errorf("Wrap(nil, \"no error\"): got %#v, expected nil", got)
+ }
+}
+
+func TestWrap(t *testing.T) {
+ tests := []struct {
+ err error
+ message string
+ want string
+ }{
+ {io.EOF, "read error", "read error: EOF"},
+ {Wrap(io.EOF, "read error"), "client error", "client error: read error: EOF"},
+ }
+
+ for _, tt := range tests {
+ got := Wrap(tt.err, tt.message).Error()
+ if got != tt.want {
+ t.Errorf("Wrap(%v, %q): got: %v, want %v", tt.err, tt.message, got, tt.want)
+ }
+ }
+}
+
+type nilError struct{}
+
+func (nilError) Error() string { return "nil error" }
+
+func TestCause(t *testing.T) {
+ x := New("error")
+ tests := []struct {
+ err error
+ want error
+ }{{
+ // nil error is nil
+ err: nil,
+ want: nil,
+ }, {
+ // explicit nil error is nil
+ err: (error)(nil),
+ want: nil,
+ }, {
+ // typed nil is nil
+ err: (*nilError)(nil),
+ want: (*nilError)(nil),
+ }, {
+ // uncaused error is unaffected
+ err: io.EOF,
+ want: io.EOF,
+ }, {
+ // caused error returns cause
+ err: Wrap(io.EOF, "ignored"),
+ want: io.EOF,
+ }, {
+ err: x, // return from errors.New
+ want: x,
+ }, {
+ WithMessage(nil, "whoops"),
+ nil,
+ }, {
+ WithMessage(io.EOF, "whoops"),
+ io.EOF,
+ }, {
+ WithStack(nil),
+ nil,
+ }, {
+ WithStack(io.EOF),
+ io.EOF,
+ }}
+
+ for i, tt := range tests {
+ got := Cause(tt.err)
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("test %d: got %#v, want %#v", i+1, got, tt.want)
+ }
+ }
+}
+
+func TestWrapfNil(t *testing.T) {
+ got := Wrapf(nil, "no error")
+ if got != nil {
+ t.Errorf("Wrapf(nil, \"no error\"): got %#v, expected nil", got)
+ }
+}
+
+func TestWrapf(t *testing.T) {
+ tests := []struct {
+ err error
+ message string
+ want string
+ }{
+ {io.EOF, "read error", "read error: EOF"},
+ {Wrapf(io.EOF, "read error without format specifiers"), "client error", "client error: read error without format specifiers: EOF"},
+ {Wrapf(io.EOF, "read error with %d format specifier", 1), "client error", "client error: read error with 1 format specifier: EOF"},
+ }
+
+ for _, tt := range tests {
+ got := Wrapf(tt.err, tt.message).Error()
+ if got != tt.want {
+ t.Errorf("Wrapf(%v, %q): got: %v, want %v", tt.err, tt.message, got, tt.want)
+ }
+ }
+}
+
+func TestErrorf(t *testing.T) {
+ tests := []struct {
+ err error
+ want string
+ }{
+ {Errorf("read error without format specifiers"), "read error without format specifiers"},
+ {Errorf("read error with %d format specifier", 1), "read error with 1 format specifier"},
+ }
+
+ for _, tt := range tests {
+ got := tt.err.Error()
+ if got != tt.want {
+ t.Errorf("Errorf(%v): got: %q, want %q", tt.err, got, tt.want)
+ }
+ }
+}
+
+func TestWithStackNil(t *testing.T) {
+ got := WithStack(nil)
+ if got != nil {
+ t.Errorf("WithStack(nil): got %#v, expected nil", got)
+ }
+}
+
+func TestWithStack(t *testing.T) {
+ tests := []struct {
+ err error
+ want string
+ }{
+ {io.EOF, "EOF"},
+ {WithStack(io.EOF), "EOF"},
+ }
+
+ for _, tt := range tests {
+ got := WithStack(tt.err).Error()
+ if got != tt.want {
+ t.Errorf("WithStack(%v): got: %v, want %v", tt.err, got, tt.want)
+ }
+ }
+}
+
+func TestWithMessageNil(t *testing.T) {
+ got := WithMessage(nil, "no error")
+ if got != nil {
+ t.Errorf("WithMessage(nil, \"no error\"): got %#v, expected nil", got)
+ }
+}
+
+func TestWithMessage(t *testing.T) {
+ tests := []struct {
+ err error
+ message string
+ want string
+ }{
+ {io.EOF, "read error", "read error: EOF"},
+ {WithMessage(io.EOF, "read error"), "client error", "client error: read error: EOF"},
+ }
+
+ for _, tt := range tests {
+ got := WithMessage(tt.err, tt.message).Error()
+ if got != tt.want {
+ t.Errorf("WithMessage(%v, %q): got: %q, want %q", tt.err, tt.message, got, tt.want)
+ }
+ }
+
+}
+
+// errors.New, etc values are not expected to be compared by value
+// but the change in errors#27 made them incomparable. Assert that
+// various kinds of errors have a functional equality operator, even
+// if the result of that equality is always false.
+func TestErrorEquality(t *testing.T) {
+ vals := []error{
+ nil,
+ io.EOF,
+ errors.New("EOF"),
+ New("EOF"),
+ Errorf("EOF"),
+ Wrap(io.EOF, "EOF"),
+ Wrapf(io.EOF, "EOF%d", 2),
+ WithMessage(nil, "whoops"),
+ WithMessage(io.EOF, "whoops"),
+ WithStack(io.EOF),
+ WithStack(nil),
+ }
+
+ for i := range vals {
+ for j := range vals {
+ _ = vals[i] == vals[j] // mustn't panic
+ }
+ }
+}
diff --git a/vendor/github.com/pkg/errors/example_test.go b/vendor/github.com/pkg/errors/example_test.go
new file mode 100644
index 0000000..c1fc13e
--- /dev/null
+++ b/vendor/github.com/pkg/errors/example_test.go
@@ -0,0 +1,205 @@
+package errors_test
+
+import (
+ "fmt"
+
+ "github.com/pkg/errors"
+)
+
+func ExampleNew() {
+ err := errors.New("whoops")
+ fmt.Println(err)
+
+ // Output: whoops
+}
+
+func ExampleNew_printf() {
+ err := errors.New("whoops")
+ fmt.Printf("%+v", err)
+
+ // Example output:
+ // whoops
+ // github.com/pkg/errors_test.ExampleNew_printf
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:17
+ // testing.runExample
+ // /home/dfc/go/src/testing/example.go:114
+ // testing.RunExamples
+ // /home/dfc/go/src/testing/example.go:38
+ // testing.(*M).Run
+ // /home/dfc/go/src/testing/testing.go:744
+ // main.main
+ // /github.com/pkg/errors/_test/_testmain.go:106
+ // runtime.main
+ // /home/dfc/go/src/runtime/proc.go:183
+ // runtime.goexit
+ // /home/dfc/go/src/runtime/asm_amd64.s:2059
+}
+
+func ExampleWithMessage() {
+ cause := errors.New("whoops")
+ err := errors.WithMessage(cause, "oh noes")
+ fmt.Println(err)
+
+ // Output: oh noes: whoops
+}
+
+func ExampleWithStack() {
+ cause := errors.New("whoops")
+ err := errors.WithStack(cause)
+ fmt.Println(err)
+
+ // Output: whoops
+}
+
+func ExampleWithStack_printf() {
+ cause := errors.New("whoops")
+ err := errors.WithStack(cause)
+ fmt.Printf("%+v", err)
+
+ // Example Output:
+ // whoops
+ // github.com/pkg/errors_test.ExampleWithStack_printf
+ // /home/fabstu/go/src/github.com/pkg/errors/example_test.go:55
+ // testing.runExample
+ // /usr/lib/go/src/testing/example.go:114
+ // testing.RunExamples
+ // /usr/lib/go/src/testing/example.go:38
+ // testing.(*M).Run
+ // /usr/lib/go/src/testing/testing.go:744
+ // main.main
+ // github.com/pkg/errors/_test/_testmain.go:106
+ // runtime.main
+ // /usr/lib/go/src/runtime/proc.go:183
+ // runtime.goexit
+ // /usr/lib/go/src/runtime/asm_amd64.s:2086
+ // github.com/pkg/errors_test.ExampleWithStack_printf
+ // /home/fabstu/go/src/github.com/pkg/errors/example_test.go:56
+ // testing.runExample
+ // /usr/lib/go/src/testing/example.go:114
+ // testing.RunExamples
+ // /usr/lib/go/src/testing/example.go:38
+ // testing.(*M).Run
+ // /usr/lib/go/src/testing/testing.go:744
+ // main.main
+ // github.com/pkg/errors/_test/_testmain.go:106
+ // runtime.main
+ // /usr/lib/go/src/runtime/proc.go:183
+ // runtime.goexit
+ // /usr/lib/go/src/runtime/asm_amd64.s:2086
+}
+
+func ExampleWrap() {
+ cause := errors.New("whoops")
+ err := errors.Wrap(cause, "oh noes")
+ fmt.Println(err)
+
+ // Output: oh noes: whoops
+}
+
+func fn() error {
+ e1 := errors.New("error")
+ e2 := errors.Wrap(e1, "inner")
+ e3 := errors.Wrap(e2, "middle")
+ return errors.Wrap(e3, "outer")
+}
+
+func ExampleCause() {
+ err := fn()
+ fmt.Println(err)
+ fmt.Println(errors.Cause(err))
+
+ // Output: outer: middle: inner: error
+ // error
+}
+
+func ExampleWrap_extended() {
+ err := fn()
+ fmt.Printf("%+v\n", err)
+
+ // Example output:
+ // error
+ // github.com/pkg/errors_test.fn
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:47
+ // github.com/pkg/errors_test.ExampleCause_printf
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:63
+ // testing.runExample
+ // /home/dfc/go/src/testing/example.go:114
+ // testing.RunExamples
+ // /home/dfc/go/src/testing/example.go:38
+ // testing.(*M).Run
+ // /home/dfc/go/src/testing/testing.go:744
+ // main.main
+ // /github.com/pkg/errors/_test/_testmain.go:104
+ // runtime.main
+ // /home/dfc/go/src/runtime/proc.go:183
+ // runtime.goexit
+ // /home/dfc/go/src/runtime/asm_amd64.s:2059
+ // github.com/pkg/errors_test.fn
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:48: inner
+ // github.com/pkg/errors_test.fn
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:49: middle
+ // github.com/pkg/errors_test.fn
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:50: outer
+}
+
+func ExampleWrapf() {
+ cause := errors.New("whoops")
+ err := errors.Wrapf(cause, "oh noes #%d", 2)
+ fmt.Println(err)
+
+ // Output: oh noes #2: whoops
+}
+
+func ExampleErrorf_extended() {
+ err := errors.Errorf("whoops: %s", "foo")
+ fmt.Printf("%+v", err)
+
+ // Example output:
+ // whoops: foo
+ // github.com/pkg/errors_test.ExampleErrorf
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:101
+ // testing.runExample
+ // /home/dfc/go/src/testing/example.go:114
+ // testing.RunExamples
+ // /home/dfc/go/src/testing/example.go:38
+ // testing.(*M).Run
+ // /home/dfc/go/src/testing/testing.go:744
+ // main.main
+ // /github.com/pkg/errors/_test/_testmain.go:102
+ // runtime.main
+ // /home/dfc/go/src/runtime/proc.go:183
+ // runtime.goexit
+ // /home/dfc/go/src/runtime/asm_amd64.s:2059
+}
+
+func Example_stackTrace() {
+ type stackTracer interface {
+ StackTrace() errors.StackTrace
+ }
+
+ err, ok := errors.Cause(fn()).(stackTracer)
+ if !ok {
+ panic("oops, err does not implement stackTracer")
+ }
+
+ st := err.StackTrace()
+ fmt.Printf("%+v", st[0:2]) // top two frames
+
+ // Example output:
+ // github.com/pkg/errors_test.fn
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:47
+ // github.com/pkg/errors_test.Example_stackTrace
+ // /home/dfc/src/github.com/pkg/errors/example_test.go:127
+}
+
+func ExampleCause_printf() {
+ err := errors.Wrap(func() error {
+ return func() error {
+ return errors.Errorf("hello %s", fmt.Sprintf("world"))
+ }()
+ }(), "failed")
+
+ fmt.Printf("%v", err)
+
+ // Output: failed: hello world
+}
diff --git a/vendor/github.com/pkg/errors/format_test.go b/vendor/github.com/pkg/errors/format_test.go
new file mode 100644
index 0000000..15fd7d8
--- /dev/null
+++ b/vendor/github.com/pkg/errors/format_test.go
@@ -0,0 +1,535 @@
+package errors
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "regexp"
+ "strings"
+ "testing"
+)
+
+func TestFormatNew(t *testing.T) {
+ tests := []struct {
+ error
+ format string
+ want string
+ }{{
+ New("error"),
+ "%s",
+ "error",
+ }, {
+ New("error"),
+ "%v",
+ "error",
+ }, {
+ New("error"),
+ "%+v",
+ "error\n" +
+ "github.com/pkg/errors.TestFormatNew\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:26",
+ }, {
+ New("error"),
+ "%q",
+ `"error"`,
+ }}
+
+ for i, tt := range tests {
+ testFormatRegexp(t, i, tt.error, tt.format, tt.want)
+ }
+}
+
+func TestFormatErrorf(t *testing.T) {
+ tests := []struct {
+ error
+ format string
+ want string
+ }{{
+ Errorf("%s", "error"),
+ "%s",
+ "error",
+ }, {
+ Errorf("%s", "error"),
+ "%v",
+ "error",
+ }, {
+ Errorf("%s", "error"),
+ "%+v",
+ "error\n" +
+ "github.com/pkg/errors.TestFormatErrorf\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:56",
+ }}
+
+ for i, tt := range tests {
+ testFormatRegexp(t, i, tt.error, tt.format, tt.want)
+ }
+}
+
+func TestFormatWrap(t *testing.T) {
+ tests := []struct {
+ error
+ format string
+ want string
+ }{{
+ Wrap(New("error"), "error2"),
+ "%s",
+ "error2: error",
+ }, {
+ Wrap(New("error"), "error2"),
+ "%v",
+ "error2: error",
+ }, {
+ Wrap(New("error"), "error2"),
+ "%+v",
+ "error\n" +
+ "github.com/pkg/errors.TestFormatWrap\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:82",
+ }, {
+ Wrap(io.EOF, "error"),
+ "%s",
+ "error: EOF",
+ }, {
+ Wrap(io.EOF, "error"),
+ "%v",
+ "error: EOF",
+ }, {
+ Wrap(io.EOF, "error"),
+ "%+v",
+ "EOF\n" +
+ "error\n" +
+ "github.com/pkg/errors.TestFormatWrap\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:96",
+ }, {
+ Wrap(Wrap(io.EOF, "error1"), "error2"),
+ "%+v",
+ "EOF\n" +
+ "error1\n" +
+ "github.com/pkg/errors.TestFormatWrap\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:103\n",
+ }, {
+ Wrap(New("error with space"), "context"),
+ "%q",
+ `"context: error with space"`,
+ }}
+
+ for i, tt := range tests {
+ testFormatRegexp(t, i, tt.error, tt.format, tt.want)
+ }
+}
+
+func TestFormatWrapf(t *testing.T) {
+ tests := []struct {
+ error
+ format string
+ want string
+ }{{
+ Wrapf(io.EOF, "error%d", 2),
+ "%s",
+ "error2: EOF",
+ }, {
+ Wrapf(io.EOF, "error%d", 2),
+ "%v",
+ "error2: EOF",
+ }, {
+ Wrapf(io.EOF, "error%d", 2),
+ "%+v",
+ "EOF\n" +
+ "error2\n" +
+ "github.com/pkg/errors.TestFormatWrapf\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:134",
+ }, {
+ Wrapf(New("error"), "error%d", 2),
+ "%s",
+ "error2: error",
+ }, {
+ Wrapf(New("error"), "error%d", 2),
+ "%v",
+ "error2: error",
+ }, {
+ Wrapf(New("error"), "error%d", 2),
+ "%+v",
+ "error\n" +
+ "github.com/pkg/errors.TestFormatWrapf\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:149",
+ }}
+
+ for i, tt := range tests {
+ testFormatRegexp(t, i, tt.error, tt.format, tt.want)
+ }
+}
+
+func TestFormatWithStack(t *testing.T) {
+ tests := []struct {
+ error
+ format string
+ want []string
+ }{{
+ WithStack(io.EOF),
+ "%s",
+ []string{"EOF"},
+ }, {
+ WithStack(io.EOF),
+ "%v",
+ []string{"EOF"},
+ }, {
+ WithStack(io.EOF),
+ "%+v",
+ []string{"EOF",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:175"},
+ }, {
+ WithStack(New("error")),
+ "%s",
+ []string{"error"},
+ }, {
+ WithStack(New("error")),
+ "%v",
+ []string{"error"},
+ }, {
+ WithStack(New("error")),
+ "%+v",
+ []string{"error",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:189",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:189"},
+ }, {
+ WithStack(WithStack(io.EOF)),
+ "%+v",
+ []string{"EOF",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:197",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:197"},
+ }, {
+ WithStack(WithStack(Wrapf(io.EOF, "message"))),
+ "%+v",
+ []string{"EOF",
+ "message",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:205",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:205",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:205"},
+ }, {
+ WithStack(Errorf("error%d", 1)),
+ "%+v",
+ []string{"error1",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:216",
+ "github.com/pkg/errors.TestFormatWithStack\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:216"},
+ }}
+
+ for i, tt := range tests {
+ testFormatCompleteCompare(t, i, tt.error, tt.format, tt.want, true)
+ }
+}
+
+func TestFormatWithMessage(t *testing.T) {
+ tests := []struct {
+ error
+ format string
+ want []string
+ }{{
+ WithMessage(New("error"), "error2"),
+ "%s",
+ []string{"error2: error"},
+ }, {
+ WithMessage(New("error"), "error2"),
+ "%v",
+ []string{"error2: error"},
+ }, {
+ WithMessage(New("error"), "error2"),
+ "%+v",
+ []string{
+ "error",
+ "github.com/pkg/errors.TestFormatWithMessage\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:244",
+ "error2"},
+ }, {
+ WithMessage(io.EOF, "addition1"),
+ "%s",
+ []string{"addition1: EOF"},
+ }, {
+ WithMessage(io.EOF, "addition1"),
+ "%v",
+ []string{"addition1: EOF"},
+ }, {
+ WithMessage(io.EOF, "addition1"),
+ "%+v",
+ []string{"EOF", "addition1"},
+ }, {
+ WithMessage(WithMessage(io.EOF, "addition1"), "addition2"),
+ "%v",
+ []string{"addition2: addition1: EOF"},
+ }, {
+ WithMessage(WithMessage(io.EOF, "addition1"), "addition2"),
+ "%+v",
+ []string{"EOF", "addition1", "addition2"},
+ }, {
+ Wrap(WithMessage(io.EOF, "error1"), "error2"),
+ "%+v",
+ []string{"EOF", "error1", "error2",
+ "github.com/pkg/errors.TestFormatWithMessage\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:272"},
+ }, {
+ WithMessage(Errorf("error%d", 1), "error2"),
+ "%+v",
+ []string{"error1",
+ "github.com/pkg/errors.TestFormatWithMessage\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:278",
+ "error2"},
+ }, {
+ WithMessage(WithStack(io.EOF), "error"),
+ "%+v",
+ []string{
+ "EOF",
+ "github.com/pkg/errors.TestFormatWithMessage\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:285",
+ "error"},
+ }, {
+ WithMessage(Wrap(WithStack(io.EOF), "inside-error"), "outside-error"),
+ "%+v",
+ []string{
+ "EOF",
+ "github.com/pkg/errors.TestFormatWithMessage\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:293",
+ "inside-error",
+ "github.com/pkg/errors.TestFormatWithMessage\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:293",
+ "outside-error"},
+ }}
+
+ for i, tt := range tests {
+ testFormatCompleteCompare(t, i, tt.error, tt.format, tt.want, true)
+ }
+}
+
+func TestFormatGeneric(t *testing.T) {
+ starts := []struct {
+ err error
+ want []string
+ }{
+ {New("new-error"), []string{
+ "new-error",
+ "github.com/pkg/errors.TestFormatGeneric\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:315"},
+ }, {Errorf("errorf-error"), []string{
+ "errorf-error",
+ "github.com/pkg/errors.TestFormatGeneric\n" +
+ "\t.+/github.com/pkg/errors/format_test.go:319"},
+ }, {errors.New("errors-new-error"), []string{
+ "errors-new-error"},
+ },
+ }
+
+ wrappers := []wrapper{
+ {
+ func(err error) error { return WithMessage(err, "with-message") },
+ []string{"with-message"},
+ }, {
+ func(err error) error { return WithStack(err) },
+ []string{
+ "github.com/pkg/errors.(func·002|TestFormatGeneric.func2)\n\t" +
+ ".+/github.com/pkg/errors/format_test.go:333",
+ },
+ }, {
+ func(err error) error { return Wrap(err, "wrap-error") },
+ []string{
+ "wrap-error",
+ "github.com/pkg/errors.(func·003|TestFormatGeneric.func3)\n\t" +
+ ".+/github.com/pkg/errors/format_test.go:339",
+ },
+ }, {
+ func(err error) error { return Wrapf(err, "wrapf-error%d", 1) },
+ []string{
+ "wrapf-error1",
+ "github.com/pkg/errors.(func·004|TestFormatGeneric.func4)\n\t" +
+ ".+/github.com/pkg/errors/format_test.go:346",
+ },
+ },
+ }
+
+ for s := range starts {
+ err := starts[s].err
+ want := starts[s].want
+ testFormatCompleteCompare(t, s, err, "%+v", want, false)
+ testGenericRecursive(t, err, want, wrappers, 3)
+ }
+}
+
+func testFormatRegexp(t *testing.T, n int, arg interface{}, format, want string) {
+ got := fmt.Sprintf(format, arg)
+ gotLines := strings.SplitN(got, "\n", -1)
+ wantLines := strings.SplitN(want, "\n", -1)
+
+ if len(wantLines) > len(gotLines) {
+ t.Errorf("test %d: wantLines(%d) > gotLines(%d):\n got: %q\nwant: %q", n+1, len(wantLines), len(gotLines), got, want)
+ return
+ }
+
+ for i, w := range wantLines {
+ match, err := regexp.MatchString(w, gotLines[i])
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !match {
+ t.Errorf("test %d: line %d: fmt.Sprintf(%q, err):\n got: %q\nwant: %q", n+1, i+1, format, got, want)
+ }
+ }
+}
+
+var stackLineR = regexp.MustCompile(`\.`)
+
+// parseBlocks parses input into a slice, where:
+// - incase entry contains a newline, its a stacktrace
+// - incase entry contains no newline, its a solo line.
+//
+// Detecting stack boundaries only works incase the WithStack-calls are
+// to be found on the same line, thats why it is optionally here.
+//
+// Example use:
+//
+// for _, e := range blocks {
+// if strings.ContainsAny(e, "\n") {
+// // Match as stack
+// } else {
+// // Match as line
+// }
+// }
+//
+func parseBlocks(input string, detectStackboundaries bool) ([]string, error) {
+ var blocks []string
+
+ stack := ""
+ wasStack := false
+ lines := map[string]bool{} // already found lines
+
+ for _, l := range strings.Split(input, "\n") {
+ isStackLine := stackLineR.MatchString