Skip to content

An improperly referenced variable should raise and error (so we can fix it) #3206

Closed

Description

@erikerikson

This is a Bug Report

Description

  • What went wrong?
    I messed up and referenced a variable incorrectly. As a result, rather than an error about an ungroundable variable, I got the following:
  Serverless Error ---------------------------------------
 
     An error occurred while provisioning your stack: ScrapeProductsLambdaFunction
     - Value of property Variables must be an object with
     String (or simple type) properties.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
 
  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       7.2.0
     Serverless Version: 1.5.1
  • What did you expect should have happened?
    I expect to get an error that variable "whatever.whoever" could not be found.

This appears to result from:
https://github.com/serverless/serverless/blob/master/lib/classes/Variables.js#L215
AND/OR a failure to follow this line:
https://github.com/serverless/serverless/blob/master/lib/classes/Variables.js#L218
with a check of whether the result is undefined.

  • What was the config you used?

A complex one... This should reproduce:

frameworkVersion: '>=1.0.0 <2.0.0'

service: my-service

custom:
  aVar: 'foo'

provider:
  name: aws
  deploymentBucket: ${self:custom.aVar.bar}

Additional Data

  • Serverless Framework Version you're using: see above
  • Operating System: see above
  • Stack Trace: see above
  • Provider Error messages: see above

Activity

  1. erikerikson commented on Feb 8, 2017

    @erikerikson
    ContributorAuthor

    Here is the sls project that was failing to deploy:
    https://github.com/Nordstrom/hello-retail/pull/26/files

    I had erroneously omitted .custom from:
    ${self:custom.retailStream.custom.exportRetailStreamWriterArn}

    (i.e. the wrong value was ${self:custom.retailStream.exportRetailStreamWriterArn} which is not defined)

  2. eahefnawy commented on Feb 8, 2017

    @eahefnawy
    Contributor

    @erikerikson initially we used to throw errors, but then we changed to just ignore the reference so that the new overwrite/fallback functionality would work. So if you're using the {self:a, self:b} syntax, and the first reference is invalid, it'll just be ignored (not error out) and the second reference will be used.

  3. erikerikson commented on Feb 9, 2017

    @erikerikson
    ContributorAuthor

    Thanks for the background @eahefnawy! I've added detection of failure to resolve via standard or overwrite resolution paths in #3208. I've left it as a warning so as to avoid this being a breaking change. Plus, my cross-serverless-service loading scheme causes some of them. I'll bring this up in that context.

  4. Wambosa commented on Apr 17, 2020

    @Wambosa

    This just stung me on serverless 1.67.3. The actual line of config that causes the problem was the global env variables section. It was a rather simple configuration. Surprised to get a hollow error message.

    serverless.yml

      custom:
        stageVars: 'stagevars.yml'
      environment:
        MY_KEY: ${self:custom.stageVars.parent.myKey}
    

    stagevars.yml

    # erasing this block causes the below error
    parent:
      myKey: 123
    

    sls deploy
    output

    ...
    An error occurred: MyLambda1 - Value of property Variables must be an object with String (or simple type) properties.
    

    and on subsequent retry:
    sls deploy
    output

    ...
    An error occurred: MyLambda2 - Value of property Variables must be an object with String (or simple type) properties.
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions