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

Unified Diff: service/datastore/multiarg.go

Issue 1516173002: Fix error message from KeyForObj when passing an invalid struct. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Fix GetMetaDefault silliness Created 5 years 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
Index: service/datastore/multiarg.go
diff --git a/service/datastore/multiarg.go b/service/datastore/multiarg.go
index cc1a6726510f6817887f6539a42ba276c780e78b..ad141d3db7bd4c88becbdeb6682d89531df7bc53 100644
--- a/service/datastore/multiarg.go
+++ b/service/datastore/multiarg.go
@@ -258,23 +258,45 @@ func multiArgTypeInterface() multiArgType {
func newKeyObjErr(aid, ns string, src interface{}) (*Key, error) {
pls := getMGS(src)
- if key, _ := pls.GetMetaDefault("key", nil).(*Key); key != nil {
+ keyI, err := GetMetaDefault(pls, "key", nil)
+ if err != nil {
+ return nil, err
+ }
+ if key, _ := keyI.(*Key); key != nil {
return key, nil
}
// get kind
- kind := pls.GetMetaDefault("kind", "").(string)
+ kindI, err := GetMetaDefault(pls, "kind", "")
+ if err != nil {
+ return nil, err
+ }
+
+ kind, _ := kindI.(string)
if kind == "" {
return nil, fmt.Errorf("unable to extract $kind from %T", src)
}
// get id - allow both to be default for default keys
- sid := pls.GetMetaDefault("id", "").(string)
- iid := pls.GetMetaDefault("id", 0).(int64)
+ sidI, err := GetMetaDefault(pls, "id", "")
+ if err != nil {
+ return nil, err
+ }
+
+ iidI, err := GetMetaDefault(pls, "id", 0)
+ if err != nil {
+ return nil, err
+ }
// get parent
- par, _ := pls.GetMetaDefault("parent", nil).(*Key)
+ parI, err := GetMetaDefault(pls, "parent", nil)
+ if err != nil {
+ return nil, err
+ }
+ iid, _ := iidI.(int64)
+ sid, _ := sidI.(string)
+ par, _ := parI.(*Key)
return NewKey(aid, ns, kind, sid, iid, par), nil
}

Powered by Google App Engine
This is Rietveld 408576698