WithoutContext passes through an error if it's nil or is a normal error. If it is a multierror, then it removes all errors of context cancellation unless that's all there is. If there's one error remaining, it returns that. Otherwise it returns a new multierror with what's left.
(err error)
| 79 | // that's all there is. If there's one error remaining, it returns that. |
| 80 | // Otherwise it returns a new multierror with what's left. |
| 81 | func WithoutContext(err error) error { |
| 82 | if err == nil { |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | multiErr, ok := err.(*multierror.Error) |
| 87 | if !ok { |
| 88 | return err |
| 89 | } |
| 90 | |
| 91 | if len(multiErr.Errors) == 0 { |
| 92 | return err // unexpected |
| 93 | } |
| 94 | |
| 95 | errs := []error{} |
| 96 | for _, e := range multiErr.Errors { |
| 97 | if e == context.Canceled { |
| 98 | continue // remove |
| 99 | } |
| 100 | errs = append(errs, e) |
| 101 | } |
| 102 | |
| 103 | if len(errs) == 0 { |
| 104 | return context.Canceled |
| 105 | } |
| 106 | //if len(errs) == 1 { |
| 107 | // return errs[0] |
| 108 | //} |
| 109 | |
| 110 | return Join(errs) |
| 111 | } |
| 112 | |
| 113 | // NoContextCanceled return nil if the error is a context.Canceled. Otherwise it |
| 114 | // returns the error. |