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

Handle undefined environment variables in resolveJoins #1047

Merged
merged 4 commits into from Aug 26, 2020

Conversation

AlexHayton
Copy link
Contributor

@AlexHayton AlexHayton commented Jul 19, 2020

Suggested fix for #1048 - tested locally and it works for me.
I also added a test suite for env var handling

Fixes the following exception:

Debug: internal, implementation, error
    TypeError: Cannot read property 'Fn::Join' of undefined
    at /Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/utils/resolveJoins.js:17:28
    at Array.forEach (<anonymous>)
    at resolveJoins (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/utils/resolveJoins.js:15:28)
    at new LambdaFunction (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/lambda/LambdaFunction.js:154:56)
    at LambdaFunctionPool.get (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/lambda/LambdaFunctionPool.js:93:24)
    at Lambda.get (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/lambda/Lambda.js:60:88)
    at hapiHandler (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/events/http/HttpServer.js:511:82)
    at module.exports.internals.Manager.execute (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/toolkit.js:41:33)
    at Object.internals.handler (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/handler.js:46:48)
    at exports.execute (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/handler.js:31:36)
    at Request._lifecycle (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/request.js:312:68)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Request._execute (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/request.js:221:9)

To reproduce, simply define something in provider.environment which isn't set in your local shell:

provider:
  environment:
    MY_ENV_VAR: ${env:MY_ENV_VAR}

Fixes the following exception:
```
Debug: internal, implementation, error
    TypeError: Cannot read property 'Fn::Join' of undefined
    at /Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/utils/resolveJoins.js:17:28
    at Array.forEach (<anonymous>)
    at resolveJoins (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/utils/resolveJoins.js:15:28)
    at new LambdaFunction (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/lambda/LambdaFunction.js:154:56)
    at LambdaFunctionPool.get (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/lambda/LambdaFunctionPool.js:93:24)
    at Lambda.get (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/lambda/Lambda.js:60:88)
    at hapiHandler (/Users/alexhayton/personal/stablemaster/lambda/node_modules/serverless-offline/dist/events/http/HttpServer.js:511:82)
    at module.exports.internals.Manager.execute (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/toolkit.js:41:33)
    at Object.internals.handler (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/handler.js:46:48)
    at exports.execute (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/handler.js:31:36)
    at Request._lifecycle (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/request.js:312:68)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Request._execute (/Users/alexhayton/personal/stablemaster/lambda/node_modules/@hapi/hapi/lib/request.js:221:9)
```
@matthewberryman
Copy link

Can confirm this fixes #1048 for me.

Environment
serverless version: v1.75.1
serverless-offline version: this PR
node.js version: v14.5.0
OS: Ubuntu 20.04 (aarch64)

@bryantbiggs
Copy link
Contributor

@dherault can we get this in as 6.5.1 please? Theres also #1053 which this would supersede

@AlexHayton
Copy link
Contributor Author

Is there anything else I need to do for this PR to get accepted?

@AlexHayton
Copy link
Contributor Author

AlexHayton commented Aug 8, 2020

I've also added a test suite for this. 🎉
Checked against master branch, it is failing there (as expected). But passing here! @dherault let me know if you would like me to add more test cases!

@connorads
Copy link

I'm guessing that @dherault is away on holiday, like a lot of France in August 🌞🇫🇷

image

@connorads
Copy link

If anyone needs a temporary fix you can reference a hotfix package.

@connorads/serverless-offline which is v.6.5.0 with added fix from #1053.

package.json

  "devDependencies": {
    "@connorads/serverless-offline": "^6.5.0",
  },

serverless.yml

plugins:
  - "@connorads/serverless-offline"

@dherault dherault merged commit 56ad82b into dherault:master Aug 26, 2020
@dherault
Copy link
Owner

Thanks @AlexHayton for this amazing fix.
@connorads I was indeed in holidays nice catch!

@bryantbiggs
Copy link
Contributor

thank you @dherault !

@AlexHayton AlexHayton deleted the patch-1 branch August 26, 2020 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants