Skip to content
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

No return from getAsync... #163

Open
QAnders opened this issue Aug 3, 2018 · 6 comments
Open

No return from getAsync... #163

QAnders opened this issue Aug 3, 2018 · 6 comments
Labels
more info This may be a valid request but more information is required to resolve it.

Comments

@QAnders
Copy link

QAnders commented Aug 3, 2018

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
Copy link
Collaborator

cdhowie commented Aug 3, 2018

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
Copy link

ekf3119 commented Aug 8, 2018

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

@cdhowie
Copy link
Collaborator

cdhowie commented Aug 9, 2018

@ekf3119 With dynogels or dynogels-promisified?

@cdhowie cdhowie added the more info This may be a valid request but more information is required to resolve it. label Dec 10, 2018
@cdhowie
Copy link
Collaborator

cdhowie commented Dec 13, 2018

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

@astuyve
Copy link

astuyve commented Dec 13, 2019

@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
Copy link
Author

QAnders commented Dec 13, 2019

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()!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info This may be a valid request but more information is required to resolve it.
Projects
None yet
Development

No branches or pull requests

4 participants