clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

No return from getAsync... #163

Open QAnders opened 6 years ago

QAnders commented 6 years ago

I am using dynogels-promisified (so please let me know if this should be in another repo) and I have the below snippet in an async function but for some reason it is not returning from dynogels...

try {
        const result = await PEPPOLCountryList.getAsync(getParams);
        if (!result)
            return Promise.reject(new Error(
                'PEPPOL Country list lookup returned "null", ' +
                JSON.stringify(getParams)
        ));
        clientContext.peppol.snd.schemeID = result.get('schemeID');
    } catch (err) {
        return Promise.reject(err);
    }

I am running in in AWS Lambda Node.js v8.10 and the Lambda always times out waiting for the return...

dynogels.AWS.config is set and verified with AccessKey/Secret and region.

Using "dynogels-promisified@^1.0.4" and "dynogels@^9.0.0".

export const PEPPOLCountryList = dynogels.define('PEPPOLCountryList', {
  tableName: 'qip-' + process.env.LAMBDA_STAGE + '-peppol-country-list',
  hashKey: 'countryCd',
  rangeKey: 'peppolCd',
  schema: {
    countryCd: Joi.string(),
    peppolCd: Joi.string(),
    description: Joi.string(),
    schemeID: Joi.string()
  },
  validation: {
    // don't allow properties not defined in the schema!
    allowUnknown: false
  }
});

I get no error message and no logging that helps me track this done... Any pointers?

Thanks for a very useful package!

cdhowie commented 6 years ago

Does the same happen when using dynogels by itself?


Side note, this is an anti-pattern:

async function foo() {
  try {
    await bar();
  } catch (err) {
    return Promise.reject(err);
  }
}

A thrown exception in an async function is automatically converted into rejection. Just write:

async function foo() {
  await bar();
}

The try/catch boilerplate in your function is just adding noise and not doing anything useful.

ekf3119 commented 6 years ago

+1 to this issue. ran into the exact same situation

cdhowie commented 6 years ago

@ekf3119 With dynogels or dynogels-promisified?

cdhowie commented 5 years ago

@QAnders @ekf3119 Can either of you reproduce this with logging enabled and post a log?

astuyve commented 4 years ago

@cdhowie I'm experiencing this issue as well. Here's what I was able to get from bunyan, although I'm having a little trouble configuring the proper loglevel:

{
    "name": "globalLogger",
    "hostname": "169.254.75.205",
    "pid": 1,
    "level": 30,
    "params": {
        "TableName": "functions-table",
        "Key": {
            "functionArn": "arn:aws:lambda:{redacted}"
        }
    },
    "msg": "dynogels GET request",
    "time": "2019-12-13T08:01:13.435Z",
    "v": 0
}
QAnders commented 4 years ago
export const lookupPEPPOLCd = async (countryCd, searchScheme) => {
  try {
    const query = await PEPPOLCountryList.query(countryCd)
      .filter('schemeID')
      .contains(searchScheme)
      .execAsync()
      .then(reply => reply.Items.map(item => item.get()));
    return query[0].peppolCd;
  } catch (err) {
    return Promise.reject(err);
  }
};

Here's how I ended up coding it instead... Note the execAsync()!