lambda-api icon indicating copy to clipboard operation
lambda-api copied to clipboard

Logger is not handling missing context

Open rwhite-lightbox opened this issue 1 year ago • 2 comments

I'm using jest to unit test my project. I'm mocking the event and context and importing my handler which imports lambda-api. When certain tests fail, the lambda-api logger is looking for the context object for a few values and the context object does not exist.

This does not happen in serverless-offline or in deployed functions and I've only seen this issue in my jest unit tests.

I've added the following to the logger.js function (around line 95) and all is fine: context: (context) => { return { remaining: context && context.getRemainingTimeInMillis && context.getRemainingTimeInMillis(), function: context && context.functionName && context.functionName, memory: context && context.memoryLimitInMB && context.memoryLimitInMB, }; },

I need to finish my unit tests, but will probably create a pull-request to get myself around this.

rwhite-lightbox avatar Feb 22 '24 13:02 rwhite-lightbox

Hey @RWhite-EDR, how are you doing?

Are you planning on creating the PR or shall I take a look and write it? 🙏

naorpeled avatar May 04 '24 20:05 naorpeled

@naorpeled All set. Please let me know if you need more details. https://github.com/jeremydaly/lambda-api/pull/267

rwhite-lightbox avatar May 14 '24 14:05 rwhite-lightbox

Hey @RWhite-EDR, I gave this more thought and decided to close this issue and mark it as not planned as this isn't a real use case and should not happen.

naorpeled avatar Jun 10 '24 19:06 naorpeled