serverless-operations / serverless-step-functions

AWS Step Functions plugin for Serverless Framework ⚡️
Other
1.03k stars 204 forks source link

Serverless v2.28.1+ Breaks SLS Deploys if using CLI Options #410

Closed franklx2 closed 3 years ago

franklx2 commented 3 years ago

This is a (Bug Report / Feature Proposal)

Description

For bug reports:

TypeError: Cannot read property 'stage' of undefined at Variables.getValueFromOptions (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:639:26) at Variables.getValueFromSource (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:579:17) at Variables.splitAndGet (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:448:17) at matches.map (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:387:40) at Array.map () at Variables.populateMatches (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:387:20) at Variables.populateValue (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:418:30) at properties.filter.map (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:300:38) at Array.map () at Variables.populateVariables (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:299:8) at Variables.populateObjectImpl (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:333:30) at initialCall (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:329:40) at Variables.initialCall (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:112:20) at Variables.populateObject (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:329:17) at parse.then.serverlessFileParam (/home/frank/Documents/PPS/PAS/Serverless/pas-serverless-gateway/public/node_modules/serverless-step-functions/lib/yamlParser.js:26:62)

Similar or dependent issues:

409

Additional Data

If I downgrade to severless@2.28.0, I can deploy once again

erikgreen-x commented 3 years ago

Same issue for me, except downgrading Serverless did not work.

balutbomber commented 3 years ago

Same issue for me...downgrading to severless@2.28.0 did work for me also. NOTE: for me the issue was specific to using serverless-step-functions. Without that plugin, deployment worked....well except that my state machine was no longer recognized and deployed.

erikgreen-x commented 3 years ago

@balutbomber ours is also specific to the serverless-step-functions plugin, but wondering if it's a broader issue. If we comment out serverless-step-functions it works. Also, this is failing for us in CI (AWS CodeBuild) and on the package subcommand.

erikgreen-x commented 3 years ago

Actually, downgrading to severless@2.28.0 also worked for me. I didn't realize in my build that it was installing 2.28.7 even though I told it to install 2.28.0. I think something must have upgraded Serverless during the build, but can't locate it in the logs to prove that. But, by adding "serverless": "2.28.0" to package.json, and removing the manual installation in our build, I got the correct version installed and got past the error.

lkhari commented 3 years ago

I've made a hack that side steps the problem, assuming you are not putting cli options in your step function schema.

The error occurs on line 26 in lib/yamlParser.js: .then(serverlessFileParam => this.serverless.variables.populateObject(serverlessFileParam)

It seems the serverless populateObject fn now can't parse the cli option for some reason. I haven't had the time to look into it. But my local hack was just: .then(serverlessFileParam => this.serverless.variables.populateObject({stepFunctions: serverlessFileParam.stepFunctions})

It allows me to have my option fields in my serverless.yml and only parse the part we actually want i.e. the stepfunctions. Definitely not a long term solution.

franklx2 commented 3 years ago

Actually, downgrading to severless@2.28.0 also worked for me. I didn't realize in my build that it was installing 2.28.7 even though I told it to install 2.28.0. I think something must have upgraded Serverless during the build, but can't locate it in the logs to prove that. But, by adding "serverless": "2.28.0" to package.json, and removing the manual installation in our build, I got the correct version installed and got past the error.

I noticed that when I had auto update turned on, after each deployment it would tell me the version that it had successfully updated to. It was near the bottom of the output I believe.

KrystianOcado commented 3 years ago

Hi!

Is there an ETA for this bug? It seems like a blocker, when can we expect a fix?

Thanks!

hassaku63 commented 3 years ago

The direct cause of the error, "getValueFromOptions", contains code that expects an object to be set in "serverless.variables.options". I suspect that the problem was caused by the fact that options was set to null.

In the serverless v2.30.3 code base, the following code is relevant.

https://github.com/serverless/serverless/blob/v2.30.3/lib/classes/Variables.js#L644-L653

In the implementation in lib/classes/Variables.js of the serverless framework, Variables holds an options object as "this.options". This member variable is initialized when populateService() is called, but looking at the stack trace this time, it is not called for some unknown reason.

I verified the case where it can be deployed normally, and it seems that populateService() is called.

Finding the reason why populateService() was not called may help us get closer to the cause of the bug.

hassaku63 commented 3 years ago

It seems that this issue is caused by the "serverless" code base.

https://github.com/serverless/serverless/issues/9099

My comment above seems to be missing the point. Sorry for the confusion.

medikoo commented 3 years ago

Will be fixed internally on Framework side with https://github.com/serverless/serverless/pull/9164

pubudusj commented 3 years ago

Had this same issue in v2.30.3 and resolved by upgrading to v2.31.0

medikoo commented 3 years ago

Yes, it was fixed on Framework side with v2.31.0. I think this issue can be closed now

franklx2 commented 3 years ago

Thanks everyone. Will close the issue.