File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -40,14 +40,17 @@ func (e *Error) GoString() string {
40
40
return fmt .Sprintf ("*%#v" , * e )
41
41
}
42
42
43
- // WrappedErrors returns the list of errors that this Error is wrapping.
44
- // It is an implementation of the errwrap.Wrapper interface so that
45
- // multierror.Error can be used with that library.
43
+ // WrappedErrors returns the list of errors that this Error is wrapping. It is
44
+ // an implementation of the errwrap.Wrapper interface so that multierror.Error
45
+ // can be used with that library.
46
46
//
47
- // This method is not safe to be called concurrently and is no different
48
- // than accessing the Errors field directly. It is implemented only to
49
- // satisfy the errwrap.Wrapper interface.
47
+ // This method is not safe to be called concurrently. Unlike accessing the
48
+ // Errors field directly, this function also checks if the multierror is nil to
49
+ // prevent a null-pointer panic. It satisfies the errwrap.Wrapper interface.
50
50
func (e * Error ) WrappedErrors () []error {
51
+ if e == nil {
52
+ return nil
53
+ }
51
54
return e .Errors
52
55
}
53
56
Original file line number Diff line number Diff line change @@ -69,6 +69,11 @@ func TestErrorWrappedErrors(t *testing.T) {
69
69
if ! reflect .DeepEqual (multi .Errors , multi .WrappedErrors ()) {
70
70
t .Fatalf ("bad: %s" , multi .WrappedErrors ())
71
71
}
72
+
73
+ multi = nil
74
+ if err := multi .WrappedErrors (); err != nil {
75
+ t .Fatalf ("bad: %#v" , multi )
76
+ }
72
77
}
73
78
74
79
func TestErrorUnwrap (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments