Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: common/errors/walk.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « common/errors/tags.go ('k') | common/errors/walk_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « common/errors/tags.go ('k') | common/errors/walk_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698