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

Unified Diff: common/errors/tags.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/errors/multierror.go ('k') | common/errors/walk.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/errors/tags.go
diff --git a/common/errors/tags.go b/common/errors/tags.go
index b80f135c94bda7fa9280987201735df73a0155ed..ce963d88a7c8a15eb41c49372cb4fc630c79f62f 100644
--- a/common/errors/tags.go
+++ b/common/errors/tags.go
@@ -4,12 +4,9 @@
package errors
-type (
- // TagKeyOrValue is used for functions taking either a TagKey or a TagValue.
- TagKeyOrValue interface {
- isTagKeyOrValue()
- }
+import "sort"
+type (
tagDescription struct {
description string
}
@@ -18,6 +15,8 @@ type (
// errors. See NewTag for details.
TagKey *tagDescription
+ tagKeySlice []TagKey
+
// TagValue represents a (tag, value) to be used with Annotate.Tag, or may be
// applied to an error directly with the Apply method.
//
@@ -36,6 +35,12 @@ type (
}
)
+var _ sort.Interface = tagKeySlice(nil)
+
+func (s tagKeySlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
+func (s tagKeySlice) Len() int { return len(s) }
+func (s tagKeySlice) Less(i, j int) bool { return s[i].description < s[j].description }
+
// TagValueIn will retrieve the tagged value from the error that's associated
// with this key, and a boolean indicating if the tag was present or not.
func TagValueIn(t TagKey, err error) (value interface{}, ok bool) {
@@ -54,7 +59,7 @@ func TagValueIn(t TagKey, err error) (value interface{}, ok bool) {
func (t TagValue) GenerateErrorTagValue() TagValue { return t }
// Apply applies this tag value (key+value) directly to the error. This is
-// a shortcut for `errors.Annotate(err).Tag(t).Err()`.
+// a shortcut for `errors.Annotate(err, "").Tag(t).Err()`.
func (t TagValue) Apply(err error) error {
if err == nil {
return nil
@@ -63,11 +68,6 @@ func (t TagValue) Apply(err error) error {
return a.Tag(t).Err()
}
-// MkTagValue is a shortcut for errors.TagValue{Key: key, Value: val}.
-func MkTagValue(key TagKey, val interface{}) TagValue {
- return TagValue{key, val}
-}
-
// BoolTag is an error tag implementation which holds a boolean value.
//
// It should be constructed like:
@@ -118,7 +118,7 @@ func (b BoolTag) In(err error) bool {
// type SomeType int
// type myTag struct { Key errors.TagKey }
// func (m myTag) With(value SomeType) errors.TagValue {
-// return errors.MkTagValue(vm.Key, value)
+// return errors.TagValue{Key: vm.Key, Value: value}
// }
// func (m myTag) In(err error) (v SomeType, ok bool) {
// d, ok := errors.TagValueIn(m.Key, err)
« no previous file with comments | « common/errors/multierror.go ('k') | common/errors/walk.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698