https://github.com/pkg/errors/compare/v0.8.0...v0.8.1
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -150,7 +150,7 @@ github.com/prometheus/client_model 6f3806018612930941127f2a7c6c |
| 150 | 150 |
github.com/prometheus/common 7600349dcfe1abd18d72d3a1770870d9800a7801 |
| 151 | 151 |
github.com/prometheus/procfs 7d6f385de8bea29190f15ba9931442a0eaef9af7 |
| 152 | 152 |
github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1 |
| 153 |
-github.com/pkg/errors 645ef00459ed84a119197bfb8d8205042c6df63d # v0.8.0 |
|
| 153 |
+github.com/pkg/errors ba968bfe8b2f7e042a574c888954fccecfa385b4 # v0.8.1 |
|
| 154 | 154 |
github.com/grpc-ecosystem/go-grpc-prometheus c225b8c3b01faf2899099b768856a9e916e5087b # v1.2.0 |
| 155 | 155 |
|
| 156 | 156 |
# cli |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-# errors [](https://travis-ci.org/pkg/errors) [](https://ci.appveyor.com/project/davecheney/errors/branch/master) [](http://godoc.org/github.com/pkg/errors) [](https://goreportcard.com/report/github.com/pkg/errors) |
|
| 1 |
+# errors [](https://travis-ci.org/pkg/errors) [](https://ci.appveyor.com/project/davecheney/errors/branch/master) [](http://godoc.org/github.com/pkg/errors) [](https://goreportcard.com/report/github.com/pkg/errors) [](https://sourcegraph.com/github.com/pkg/errors?badge) |
|
| 2 | 2 |
|
| 3 | 3 |
Package errors provides simple error handling primitives. |
| 4 | 4 |
|
| ... | ... |
@@ -47,6 +47,6 @@ We welcome pull requests, bug fixes and issue reports. With that said, the bar f |
| 47 | 47 |
|
| 48 | 48 |
Before proposing a change, please discuss your change by raising an issue. |
| 49 | 49 |
|
| 50 |
-## Licence |
|
| 50 |
+## License |
|
| 51 | 51 |
|
| 52 | 52 |
BSD-2-Clause |
| ... | ... |
@@ -6,7 +6,7 @@ |
| 6 | 6 |
// return err |
| 7 | 7 |
// } |
| 8 | 8 |
// |
| 9 |
-// which applied recursively up the call stack results in error reports |
|
| 9 |
+// which when applied recursively up the call stack results in error reports |
|
| 10 | 10 |
// without context or debugging information. The errors package allows |
| 11 | 11 |
// programmers to add context to the failure path in their code in a way |
| 12 | 12 |
// that does not destroy the original value of the error. |
| ... | ... |
@@ -15,16 +15,17 @@ |
| 15 | 15 |
// |
| 16 | 16 |
// The errors.Wrap function returns a new error that adds context to the |
| 17 | 17 |
// original error by recording a stack trace at the point Wrap is called, |
| 18 |
-// and the supplied message. For example |
|
| 18 |
+// together with the supplied message. For example |
|
| 19 | 19 |
// |
| 20 | 20 |
// _, err := ioutil.ReadAll(r) |
| 21 | 21 |
// if err != nil {
|
| 22 | 22 |
// return errors.Wrap(err, "read failed") |
| 23 | 23 |
// } |
| 24 | 24 |
// |
| 25 |
-// If additional control is required the errors.WithStack and errors.WithMessage |
|
| 26 |
-// functions destructure errors.Wrap into its component operations of annotating |
|
| 27 |
-// an error with a stack trace and an a message, respectively. |
|
| 25 |
+// If additional control is required, the errors.WithStack and |
|
| 26 |
+// errors.WithMessage functions destructure errors.Wrap into its component |
|
| 27 |
+// operations: annotating an error with a stack trace and with a message, |
|
| 28 |
+// respectively. |
|
| 28 | 29 |
// |
| 29 | 30 |
// Retrieving the cause of an error |
| 30 | 31 |
// |
| ... | ... |
@@ -38,7 +39,7 @@ |
| 38 | 38 |
// } |
| 39 | 39 |
// |
| 40 | 40 |
// can be inspected by errors.Cause. errors.Cause will recursively retrieve |
| 41 |
-// the topmost error which does not implement causer, which is assumed to be |
|
| 41 |
+// the topmost error that does not implement causer, which is assumed to be |
|
| 42 | 42 |
// the original cause. For example: |
| 43 | 43 |
// |
| 44 | 44 |
// switch err := errors.Cause(err).(type) {
|
| ... | ... |
@@ -48,16 +49,16 @@ |
| 48 | 48 |
// // unknown error |
| 49 | 49 |
// } |
| 50 | 50 |
// |
| 51 |
-// causer interface is not exported by this package, but is considered a part |
|
| 52 |
-// of stable public API. |
|
| 51 |
+// Although the causer interface is not exported by this package, it is |
|
| 52 |
+// considered a part of its stable public interface. |
|
| 53 | 53 |
// |
| 54 | 54 |
// Formatted printing of errors |
| 55 | 55 |
// |
| 56 | 56 |
// All error values returned from this package implement fmt.Formatter and can |
| 57 |
-// be formatted by the fmt package. The following verbs are supported |
|
| 57 |
+// be formatted by the fmt package. The following verbs are supported: |
|
| 58 | 58 |
// |
| 59 | 59 |
// %s print the error. If the error has a Cause it will be |
| 60 |
-// printed recursively |
|
| 60 |
+// printed recursively. |
|
| 61 | 61 |
// %v see %s |
| 62 | 62 |
// %+v extended format. Each Frame of the error's StackTrace will |
| 63 | 63 |
// be printed in detail. |
| ... | ... |
@@ -65,13 +66,13 @@ |
| 65 | 65 |
// Retrieving the stack trace of an error or wrapper |
| 66 | 66 |
// |
| 67 | 67 |
// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are |
| 68 |
-// invoked. This information can be retrieved with the following interface. |
|
| 68 |
+// invoked. This information can be retrieved with the following interface: |
|
| 69 | 69 |
// |
| 70 | 70 |
// type stackTracer interface {
|
| 71 | 71 |
// StackTrace() errors.StackTrace |
| 72 | 72 |
// } |
| 73 | 73 |
// |
| 74 |
-// Where errors.StackTrace is defined as |
|
| 74 |
+// The returned errors.StackTrace type is defined as |
|
| 75 | 75 |
// |
| 76 | 76 |
// type StackTrace []Frame |
| 77 | 77 |
// |
| ... | ... |
@@ -85,8 +86,8 @@ |
| 85 | 85 |
// } |
| 86 | 86 |
// } |
| 87 | 87 |
// |
| 88 |
-// stackTracer interface is not exported by this package, but is considered a part |
|
| 89 |
-// of stable public API. |
|
| 88 |
+// Although the stackTracer interface is not exported by this package, it is |
|
| 89 |
+// considered a part of its stable public interface. |
|
| 90 | 90 |
// |
| 91 | 91 |
// See the documentation for Frame.Format for more details. |
| 92 | 92 |
package errors |
| ... | ... |
@@ -192,7 +193,7 @@ func Wrap(err error, message string) error {
|
| 192 | 192 |
} |
| 193 | 193 |
|
| 194 | 194 |
// Wrapf returns an error annotating err with a stack trace |
| 195 |
-// at the point Wrapf is call, and the format specifier. |
|
| 195 |
+// at the point Wrapf is called, and the format specifier. |
|
| 196 | 196 |
// If err is nil, Wrapf returns nil. |
| 197 | 197 |
func Wrapf(err error, format string, args ...interface{}) error {
|
| 198 | 198 |
if err == nil {
|
| ... | ... |
@@ -220,6 +221,18 @@ func WithMessage(err error, message string) error {
|
| 220 | 220 |
} |
| 221 | 221 |
} |
| 222 | 222 |
|
| 223 |
+// WithMessagef annotates err with the format specifier. |
|
| 224 |
+// If err is nil, WithMessagef returns nil. |
|
| 225 |
+func WithMessagef(err error, format string, args ...interface{}) error {
|
|
| 226 |
+ if err == nil {
|
|
| 227 |
+ return nil |
|
| 228 |
+ } |
|
| 229 |
+ return &withMessage{
|
|
| 230 |
+ cause: err, |
|
| 231 |
+ msg: fmt.Sprintf(format, args...), |
|
| 232 |
+ } |
|
| 233 |
+} |
|
| 234 |
+ |
|
| 223 | 235 |
type withMessage struct {
|
| 224 | 236 |
cause error |
| 225 | 237 |
msg string |
| ... | ... |
@@ -46,7 +46,8 @@ func (f Frame) line() int {
|
| 46 | 46 |
// |
| 47 | 47 |
// Format accepts flags that alter the printing of some verbs, as follows: |
| 48 | 48 |
// |
| 49 |
-// %+s path of source file relative to the compile time GOPATH |
|
| 49 |
+// %+s function name and path of source file relative to the compile time |
|
| 50 |
+// GOPATH separated by \n\t (<funcname>\n\t<path>) |
|
| 50 | 51 |
// %+v equivalent to %+s:%d |
| 51 | 52 |
func (f Frame) Format(s fmt.State, verb rune) {
|
| 52 | 53 |
switch verb {
|
| ... | ... |
@@ -79,6 +80,14 @@ func (f Frame) Format(s fmt.State, verb rune) {
|
| 79 | 79 |
// StackTrace is stack of Frames from innermost (newest) to outermost (oldest). |
| 80 | 80 |
type StackTrace []Frame |
| 81 | 81 |
|
| 82 |
+// Format formats the stack of Frames according to the fmt.Formatter interface. |
|
| 83 |
+// |
|
| 84 |
+// %s lists source files for each Frame in the stack |
|
| 85 |
+// %v lists the source file and line number for each Frame in the stack |
|
| 86 |
+// |
|
| 87 |
+// Format accepts flags that alter the printing of some verbs, as follows: |
|
| 88 |
+// |
|
| 89 |
+// %+v Prints filename, function, and line number for each Frame in the stack. |
|
| 82 | 90 |
func (st StackTrace) Format(s fmt.State, verb rune) {
|
| 83 | 91 |
switch verb {
|
| 84 | 92 |
case 'v': |
| ... | ... |
@@ -136,43 +145,3 @@ func funcname(name string) string {
|
| 136 | 136 |
i = strings.Index(name, ".") |
| 137 | 137 |
return name[i+1:] |
| 138 | 138 |
} |
| 139 |
- |
|
| 140 |
-func trimGOPATH(name, file string) string {
|
|
| 141 |
- // Here we want to get the source file path relative to the compile time |
|
| 142 |
- // GOPATH. As of Go 1.6.x there is no direct way to know the compiled |
|
| 143 |
- // GOPATH at runtime, but we can infer the number of path segments in the |
|
| 144 |
- // GOPATH. We note that fn.Name() returns the function name qualified by |
|
| 145 |
- // the import path, which does not include the GOPATH. Thus we can trim |
|
| 146 |
- // segments from the beginning of the file path until the number of path |
|
| 147 |
- // separators remaining is one more than the number of path separators in |
|
| 148 |
- // the function name. For example, given: |
|
| 149 |
- // |
|
| 150 |
- // GOPATH /home/user |
|
| 151 |
- // file /home/user/src/pkg/sub/file.go |
|
| 152 |
- // fn.Name() pkg/sub.Type.Method |
|
| 153 |
- // |
|
| 154 |
- // We want to produce: |
|
| 155 |
- // |
|
| 156 |
- // pkg/sub/file.go |
|
| 157 |
- // |
|
| 158 |
- // From this we can easily see that fn.Name() has one less path separator |
|
| 159 |
- // than our desired output. We count separators from the end of the file |
|
| 160 |
- // path until it finds two more than in the function name and then move |
|
| 161 |
- // one character forward to preserve the initial path segment without a |
|
| 162 |
- // leading separator. |
|
| 163 |
- const sep = "/" |
|
| 164 |
- goal := strings.Count(name, sep) + 2 |
|
| 165 |
- i := len(file) |
|
| 166 |
- for n := 0; n < goal; n++ {
|
|
| 167 |
- i = strings.LastIndex(file[:i], sep) |
|
| 168 |
- if i == -1 {
|
|
| 169 |
- // not enough separators found, set i so that the slice expression |
|
| 170 |
- // below leaves file unmodified |
|
| 171 |
- i = -len(sep) |
|
| 172 |
- break |
|
| 173 |
- } |
|
| 174 |
- } |
|
| 175 |
- // get back to 0 or trim the leading separator |
|
| 176 |
- file = file[i+len(sep):] |
|
| 177 |
- return file |
|
| 178 |
-} |