CodeGenieApp / serverless-express

Run Express and other Node.js frameworks on AWS Serverless technologies such as Lambda, API Gateway, Lambda@Edge, and more.
https://codegenie.codes
Apache License 2.0
5.17k stars 671 forks source link

Content-Encoding: Cannot read property 'some' of undefined #373

Closed anthonyalmarza closed 3 years ago

anthonyalmarza commented 3 years ago

Hi, So I'm sometimes running into this issue where on the following line there is raising a runtime error where binarySettings.contentEncodings is undefined. https://github.com/vendia/serverless-express/blob/mainline/src/is-binary.js#L10

I'm not sure how this is happening but I've followed the trail up to the following two links if that helps. https://github.com/vendia/serverless-express/blob/mainline/src/proxy.js#L28 https://github.com/vendia/serverless-express/blob/mainline/src/index.js#L17-L22

The following is the stacktrace I'm getting back from my lambda function.

ERROR   Unhandled Promise Rejection     
{
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "TypeError: Cannot read property 'some' of undefined",
    "reason": {
        "errorType": "TypeError",
        "errorMessage": "Cannot read property 'some' of undefined",
        "stack": [
            "TypeError: Cannot read property 'some' of undefined",
            "    at /var/task/node_modules/.pnpm/@vendia/serverless-express@4.3.1/node_modules/@vendia/serverless-express/src/is-binary.js:10:40",
            "    at Array.some (<anonymous>)",
            "    at isContentEncodingBinary (/var/task/node_modules/.pnpm/@vendia/serverless-express@4.3.1/node_modules/@vendia/serverless-express/src/is-binary.js:10:6)",
            "    at isBinary (/var/task/node_modules/.pnpm/@vendia/serverless-express@4.3.1/node_modules/@vendia/serverless-express/src/is-binary.js:40:10)",
            "    at forwardResponse (/var/task/node_modules/.pnpm/@vendia/serverless-express@4.3.1/node_modules/@vendia/serverless-express/src/transport.js:17:27)",
            "    at forwardRequestToNodeServer (/var/task/node_modules/.pnpm/@vendia/serverless-express@4.3.1/node_modules/@vendia/serverless-express/src/transport.js:139:3)",
            "    at processTicksAndRejections (internal/process/task_queues.js:93:5)"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: TypeError: Cannot read property 'some' of undefined",
        "    at process.<anonymous> (/var/runtime/index.js:35:15)",
        "    at process.emit (events.js:315:20)",
        "    at process.EventEmitter.emit (domain.js:467:12)",
        "    at processPromiseRejections (internal/process/promises.js:245:33)",
        "    at processTicksAndRejections (internal/process/task_queues.js:94:32)"
    ]
}

More context around this sometimes happening is that when I remove Accept-Encoding from the headers the error is not raised. Very confusing.

Any and all help on this issue would be much appreciated.

Package deps:

"dependencies": {
    "@vendia/serverless-express": "^4.3.1",
    "compression": "^1.7.4",
    "express": "^4.17.1",
    "express-validator": "^6.9.2",
    "helmet": "^4.4.1"
  },
brett-vendia commented 3 years ago

Hi @anthonyalmarza, could you provide relevant parts from your Lambda handler? Are you setting binarySettings?

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 4.3.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: