DataDog / datadog-lambda-js

The Datadog AWS Lambda Library for Node
Apache License 2.0
113 stars 35 forks source link

isBatchItemFailure fails when lambda response is null #549

Closed matthias-pichler closed 5 months ago

matthias-pichler commented 5 months ago

Expected Behavior

It should be possible to return null from a Lambda Function

Actual Behavior

https://github.com/DataDog/datadog-lambda-js/blob/a7a56f18f9e938c3736ef4933bc2eecce3afe303/src/utils/batch-item-failures.ts#L4

this fails because typeof null === "object"

Steps to Reproduce the Problem

  1. Add the layer to a lambda function
  2. return null

Specifications

Stacktrace

 {
    "errorType": "TypeError",
    "errorMessage": "Cannot use 'in' operator to search for 'batchItemFailures' in null",
    "stack": [
        "TypeError: Cannot use 'in' operator to search for 'batchItemFailures' in null",
        "    at isBatchItemFailure (/opt/nodejs/node_modules/datadog-lambda-js/utils/batch-item-failures.js:6:29)",
        "    at /opt/nodejs/node_modules/datadog-lambda-js/index.js:243:80",
        "    at step (/opt/nodejs/node_modules/datadog-lambda-js/index.js:44:23)",
        "    at Object.next (/opt/nodejs/node_modules/datadog-lambda-js/index.js:25:53)",
        "    at fulfilled (/opt/nodejs/node_modules/datadog-lambda-js/index.js:16:58)"
    ]
}
purple4reina commented 5 months ago

@matthias-pichler-warrify Thanks for reporting this, that is indeed a problem. We'll get started on a fix right away.