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

Protect against undefined env vars when resolving joins #1057

Closed
wants to merge 2 commits into from

Conversation

nem035
Copy link

@nem035 nem035 commented Aug 4, 2020

While running sls offline on version 6.5, i came across a somewhat cryptic error:

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

Since my project doesn't use the join intrinsic function, the error wasn't particularly helpful in determining the problem.

After a bit of search, I found the cause in this PR.

The problem is that, if an environment variable is undefined, an exception is raised.

A better approach might be to either ignore undefined env vars or log them with a warning. I chose the former right now but am open to change the code as needed.

While running sls offline on version 6.5, i came across a somewhat cryptic error:

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

Since this project doesn't use the join intrinsic function, the error wasn't particularly helpful in determining the problem.

After a bit of search, I found the cause in [this PR](dherault#1032).

The problem is that, if an environment variable is `undefined`, an exception is raised.

A better approach might be to either ignore undefined env vars or log them with a warning. I chose the former right now but am open to change the code as needed.
@connorads
Copy link

Three PRs open for this now 😂
#1047 #1053 #1057

@nem035
Copy link
Author

nem035 commented Aug 6, 2020

oops :D

Feel free to merge the one that came first, I'll close mine.

@nem035 nem035 closed this Aug 6, 2020
@nem035 nem035 deleted the patch-1 branch August 6, 2020 20:28
@connorads
Copy link

I did the same thing 😁
Hopefully @dherault can merge #1047 soon 🤞

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

2 participants