英文:
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]
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论