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

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

Issue 1863973002: LogDog: Update to archival V2. (Closed) Base URL: https://github.com/luci/luci-go@grpcutil-errors
Patch Set: Code review comments, use Pub/Sub, archival staging, quality of life. Created 4 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package errors 5 package errors
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "reflect" 9 "reflect"
10 ) 10 )
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // we know that err already conforms to the error interface (or the caller's 87 // we know that err already conforms to the error interface (or the caller's
88 // method wouldn't compile), so check to see if the error's unde rlying type 88 // method wouldn't compile), so check to see if the error's unde rlying type
89 // looks like one of the special error types we implement. 89 // looks like one of the special error types we implement.
90 v := reflect.ValueOf(err) 90 v := reflect.ValueOf(err)
91 if v.Type().ConvertibleTo(multiErrorType) { 91 if v.Type().ConvertibleTo(multiErrorType) {
92 err = v.Convert(multiErrorType).Interface().(error) 92 err = v.Convert(multiErrorType).Interface().(error)
93 } 93 }
94 } 94 }
95 return err 95 return err
96 } 96 }
97
98 // Any returns true if a the filter function is true for the supplied error.
99 // If the supplied error is a MultiError, Any will recurse into it.
100 //
101 // If err is nil, Any will return false.
102 func Any(err error, fn func(error) bool) bool {
103 if err == nil {
104 return false
105 }
106
107 if fn(err) {
108 return true
109 }
110 if merr, ok := err.(MultiError); ok {
111 for _, e := range merr {
112 if Any(e, fn) {
113 return true
114 }
115 }
116 }
117 return false
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698