| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package errors | |
| 6 | |
| 7 import ( | |
| 8 "fmt" | |
| 9 ) | |
| 10 | |
| 11 // MultiError is a simple `error` implementation which represents multiple | |
| 12 // `error` objects in one. | |
| 13 type MultiError []error | |
| 14 | |
| 15 // MultiErrorFromErrors takes an error-channel, blocks on it, and returns | |
| 16 // a MultiError for any errors pushed to it over the channel, or nil if | |
| 17 // all the errors were nil. | |
| 18 func MultiErrorFromErrors(ch <-chan error) error { | |
| 19 if ch == nil { | |
| 20 return nil | |
| 21 } | |
| 22 ret := MultiError(nil) | |
| 23 for e := range ch { | |
| 24 if e == nil { | |
| 25 continue | |
| 26 } | |
| 27 ret = append(ret, e) | |
| 28 } | |
| 29 if len(ret) == 0 { | |
| 30 return nil | |
| 31 } | |
| 32 return ret | |
| 33 } | |
| 34 | |
| 35 func (m MultiError) Error() string { | |
| 36 return fmt.Sprintf("%+q", []error(m)) | |
| 37 } | |
| OLD | NEW |