| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package errors | 5 package errors |
| 6 | 6 |
| 7 // Walk performs a depth-first traversal of the supplied error, unfolding it and | 7 // Walk performs a depth-first traversal of the supplied error, unfolding it and |
| 8 // invoke the supplied callback for each layered error recursively. If the | 8 // invoke the supplied callback for each layered error recursively. If the |
| 9 // callback returns true, Walk will continue its traversal. | 9 // callback returns true, Walk will continue its traversal. |
| 10 // | 10 // |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // visited erorr. | 48 // visited erorr. |
| 49 // | 49 // |
| 50 // If err is nil, Any will return false. | 50 // If err is nil, Any will return false. |
| 51 func Any(err error, fn func(error) bool) (any bool) { | 51 func Any(err error, fn func(error) bool) (any bool) { |
| 52 Walk(err, func(err error) bool { | 52 Walk(err, func(err error) bool { |
| 53 any = fn(err) | 53 any = fn(err) |
| 54 return !any | 54 return !any |
| 55 }) | 55 }) |
| 56 return | 56 return |
| 57 } | 57 } |
| 58 | |
| 59 // Contains performs a Walk traversal of an error, returning true if it is or | |
| 60 // contains the supplied sentinel error. | |
| 61 func Contains(err, sentinel error) bool { | |
| 62 return Any(err, func(err error) bool { | |
| 63 return err == sentinel | |
| 64 }) | |
| 65 } | |
| OLD | NEW |