| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 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 validation provides a helper for performing config validations. | 5 // Package validation provides a helper for performing config validations. |
| 6 package validation | 6 package validation |
| 7 | 7 |
| 8 import ( | 8 import ( |
| 9 "fmt" | 9 "fmt" |
| 10 "strings" | 10 "strings" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 type Context struct { | 39 type Context struct { |
| 40 Logger logging.Logger // logs errors as they appear | 40 Logger logging.Logger // logs errors as they appear |
| 41 | 41 |
| 42 errors errors.MultiError // all accumulated errors | 42 errors errors.MultiError // all accumulated errors |
| 43 file string // the currently validated file | 43 file string // the currently validated file |
| 44 element []string // logical path of a sub-element we validate,
see Enter | 44 element []string // logical path of a sub-element we validate,
see Enter |
| 45 } | 45 } |
| 46 | 46 |
| 47 type fileTagType struct{ Key errors.TagKey } | 47 type fileTagType struct{ Key errors.TagKey } |
| 48 | 48 |
| 49 func (f fileTagType) With(name string) errors.TagValue { return errors.MkTagValu
e(f.Key, name) } | 49 func (f fileTagType) With(name string) errors.TagValue { |
| 50 » return errors.TagValue{Key: f.Key, Value: name} |
| 51 } |
| 50 func (f fileTagType) In(err error) (v string, ok bool) { | 52 func (f fileTagType) In(err error) (v string, ok bool) { |
| 51 d, ok := errors.TagValueIn(f.Key, err) | 53 d, ok := errors.TagValueIn(f.Key, err) |
| 52 if ok { | 54 if ok { |
| 53 v = d.(string) | 55 v = d.(string) |
| 54 } | 56 } |
| 55 return | 57 return |
| 56 } | 58 } |
| 57 | 59 |
| 58 type elementTagType struct{ Key errors.TagKey } | 60 type elementTagType struct{ Key errors.TagKey } |
| 59 | 61 |
| 60 func (e elementTagType) With(elements []string) errors.TagValue { | 62 func (e elementTagType) With(elements []string) errors.TagValue { |
| 61 » return errors.MkTagValue(e.Key, append([]string(nil), elements...)) | 63 » return errors.TagValue{Key: e.Key, Value: append([]string(nil), elements
...)} |
| 62 } | 64 } |
| 63 func (e elementTagType) In(err error) (v []string, ok bool) { | 65 func (e elementTagType) In(err error) (v []string, ok bool) { |
| 64 d, ok := errors.TagValueIn(e.Key, err) | 66 d, ok := errors.TagValueIn(e.Key, err) |
| 65 if ok { | 67 if ok { |
| 66 v = d.([]string) | 68 v = d.([]string) |
| 67 } | 69 } |
| 68 return | 70 return |
| 69 } | 71 } |
| 70 | 72 |
| 71 var fileTag = fileTagType{errors.NewTagKey("holds the file name for tests")} | 73 var fileTag = fileTagType{errors.NewTagKey("holds the file name for tests")} |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // | 135 // |
| 134 // Returns nil otherwise. | 136 // Returns nil otherwise. |
| 135 func (v *Context) Finalize() error { | 137 func (v *Context) Finalize() error { |
| 136 if len(v.errors) == 0 { | 138 if len(v.errors) == 0 { |
| 137 return nil | 139 return nil |
| 138 } | 140 } |
| 139 return &Error{ | 141 return &Error{ |
| 140 Errors: append(errors.MultiError{}, v.errors...), | 142 Errors: append(errors.MultiError{}, v.errors...), |
| 141 } | 143 } |
| 142 } | 144 } |
| OLD | NEW |