Golang – Does AppEngine Datastore GetMulti() return invalid data when it returns a MultiError?

huangapple go评论96阅读模式
英文:

Golang - Does AppEngine Datastore GetMulti() return invalid data when it returns a MultiError?

问题

我正在调用AppEngine Datastore来获取可能存储的数据;我只关心在所有多个错误条目返回错误的情况下的多个错误。如果一个多个错误的条目为nil,返回的数据是否会包含与多个错误中的错误匹配的键的错误、空或损坏的数据条目。目前它的工作正常,但我不知道可能出现什么异常情况,或者是否由于某种惯用的原因而糟糕。

英文:

I am calling into the AppEngine Datastore to get data that may or may not be stored; I am not concerned with a multi error except in the case that all of the multi error entries return an error.

err := datastore.GetMulti(context, keys, data)
if err_entries, ok := err.(appengine.MultiError); ok {
	for _, err_entry := range err_entries {
		if err_entry == nil {
			return data, nil
		}
	}
}
return data, err

My question is whether the data returned, given that one err_entry of a multi error is nil, will contain false, empty, or corrupt data entries for keys that match an error in the multi error. It works as expected for now but I don't know what potential exceptions might come up or if this is horrendous for some idiomatic reason.

答案1

得分: 2

从https://developers.google.com/appengine/docs/go/reference#MultiError中可以看到:

> 当批量操作中的特定元素存在错误时,将返回MultiError。

> 错误与输入元素一一对应;成功的元素将具有nil条目。

它永远不会有数据,每个i, err_entry要么是nil,要么是与data[i]相关联的错误。

英文:

Right from https://developers.google.com/appengine/docs/go/reference#MultiError:

> MultiError is returned by batch operations when there are errors with particular elements.
>
> Errors will be in a one-to-one correspondence with the input elements; successful elements will have a nil entry.

It will never have data, each i, err_entry is either nil or an error linked to data[i].

huangapple
  • 本文由 发表于 2014年9月7日 09:29:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/25706300.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定