diff --git a/docs/providers/aws/examples/cron/node/handler.js b/docs/providers/aws/examples/cron/node/handler.js index 5fb485788..980b35d28 100644 --- a/docs/providers/aws/examples/cron/node/handler.js +++ b/docs/providers/aws/examples/cron/node/handler.js @@ -2,5 +2,5 @@ module.exports.run = () => { const time = new Date(); - console.log(`Your cron ran ${time}`); + console.log(`Your cron ran ${time}`); // eslint-disable-line no-console }; diff --git a/lib/classes/Variables.js b/lib/classes/Variables.js index ec19da1cf..f8aa0039c 100644 --- a/lib/classes/Variables.js +++ b/lib/classes/Variables.js @@ -156,6 +156,10 @@ class Variables { const referencedFileFullPath = path.join(this.serverless.config.servicePath, referencedFileRelativePath); + if (!this.serverless.utils.fileExistsSync(referencedFileFullPath)) { + return undefined; + } + let valueToPopulate = this.serverless.utils.readFileSync(referencedFileFullPath); if (matchedFileRefString !== variableString) { let deepProperties = variableString diff --git a/lib/classes/Variables.test.js b/lib/classes/Variables.test.js index 7fab9dc78..2caec549a 100644 --- a/lib/classes/Variables.test.js +++ b/lib/classes/Variables.test.js @@ -385,6 +385,16 @@ describe('Variables', () => { expect(valueToPopulate).to.deep.equal(configYml); }); + it('should get undefined if non existing file and the second argument is true', () => { + const serverless = new Serverless(); + const tmpDirPath = testUtils.getTmpDirPath(); + + serverless.config.update({ servicePath: tmpDirPath }); + + const valueToPopulate = serverless.variables.getValueFromFile('file(./config.yml)'); + expect(valueToPopulate).to.be.equal(undefined); + }); + it('should populate non json/yml files', () => { const serverless = new Serverless(); const SUtils = new Utils();