-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataStore get with async/await returns array?? #2749
Comments
This seems a little tricky. If you call But what if you call What do you think would be a sane way to handle this? |
the problem is not the "not found" cases.. the problem is that the return value when using async/await is always an array.. but with normal get(key).then().else(); the returned objects are entities and not found is undefined.. but foo = await get(key); returns array.. i.e. [ entity ] and when not found [ undefined ] so the work around is to check if return value is not undefined, then check if it has a count array elements more than 0.. if it does, then get the first element.. then evaluate if its entity or undefined.. its a bug for async/await |
Do you have a way we could solve this? |
This is tricky because the upstream API is not returning a 404 error here. But I would handle it like this const [entity] = await datastore.get(key);
if (!entity) {
throw new Error('No entities found!');
} |
No its not.. promises work fine.. its specifically Async/Await.. |
When using await to call DataStore.get([klind,key]) the return value is always an array..
Event when the record was not found, the undefined value also comes back as an array of [ undefined ]
But when I use standard async calls, it works fine.,..
Environment details
Steps to reproduce
google-cloud
For items found it always returned as an array [ object ] or when record doesnt exisit and not found, it always returns [ undefined ]
The text was updated successfully, but these errors were encountered: