Google-cloud-node: should the catch in try/catch with async/await "work" (datastore)?

Created on 21 Nov 2017  路  3Comments  路  Source: googleapis/google-cloud-node

Environment details

  • OS: Dev - mac & windows; Deploy - AppEngine
  • Node.js version: 8.x
  • google-cloud-node version: 1.1.0

This is question -- not an issue

I'm trying to implement simple try/catch functionality with async/await.

In my case I'm using TypeScript 2.x compiling to ES6.

I have a function like this:

  public async getTestDatas(id: string): Promise<Array<ITestData>> {

    const retVal: Array<ITestData> = [];

    const datastore = await GCPUtils.getDatastore();

    const query = datastore.createQuery(DBConstant.TestDataKind)
      .filter('id', '=', id);
    try {
      const results: any[] = await datastore.runQuery(query);
      if (results.length > 0) {
        const entries: any[] = results[0];
        entries.forEach(testData => {
          retVal.push(testData as ITestData);
        });
      }
    } catch (err) {
      console.log(err);
    }

    return retVal;
  }

What I'm expecting is if there is an issue with the query -- it will land on the catch (err) { console.log(err); }

When I experience an exceptions - they generally just fail
-when debugging - it will just except out down in the datastore api code (and it's very difficult to figure out why)
-at runtime -- the process (express app) spits a ' we caught an unhandled exception and we're not going to do that forever!!!' warning

edit: I should mention most of the time these turn out to be malformed / empty keys

I'm assuming my expectations are incorrect -- but is there a way to get this working while keeping the nice try/catch syntax?

Thanks - Chad

question

All 3 comments

Hey @chadbr, thanks for asking. I think you might get a better response from a wider range of experts on StackOverflow using our tags: https://stackoverflow.com/questions/tagged/google-cloud-platform+nodejs (Maybe add on TypeScript as well).

If you do post, please link back here. I'll close this issue, but if anyone else who sees this knows the answer, of course feel free to help out :)

ok, fwiw, no responses...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicolasgarnier picture nicolasgarnier  路  4Comments

jgeewax picture jgeewax  路  4Comments

VikramTiwari picture VikramTiwari  路  3Comments

dsimmons picture dsimmons  路  4Comments

pputhran picture pputhran  路  4Comments