Skip to content

Commit a53cfa8

Browse files
authored
Merge pull request #63 from yashptel/main
Fix: Support fallback values for `${param:x, fallback}` syntax in stage parameters
2 parents 296a053 + 7b66d29 commit a53cfa8

File tree

2 files changed

+13
-10
lines changed
  • lib/configuration/variables/sources/instance-dependent
  • test/unit/lib/configuration/variables/sources/instance-dependent

2 files changed

+13
-10
lines changed

lib/configuration/variables/sources/instance-dependent/param.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,8 @@ module.exports = (serverlessInstance) => {
6363

6464
const params = await resolveParams(stage, serverlessInstance);
6565
const value = params[address] ? params[address].value : null;
66-
const result = { value };
6766

68-
if (value == null) {
69-
throw new ServerlessError(
70-
`The param "${address}" cannot be resolved from stage params. If you are using Serverless Framework Compose, make sure to run commands via Compose so that all parameters can be resolved`,
71-
'MISSING_PARAM_SOURCE_ADDRESS'
72-
);
73-
}
74-
75-
return result;
67+
return { value };
7668
},
7769
};
7870
};

test/unit/lib/configuration/variables/sources/instance-dependent/param.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/param
2929
unsupportedAddress: '${param:foo}',
3030
nonStringAddress: '${param:${self:custom.someObject}}',
3131
someObject: {},
32+
variableWithFallback: '${param:bar, "value"}',
3233
},
3334
params: stageParameters,
3435
};
@@ -145,7 +146,7 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/param
145146
it('should report with an error when the address is not supported', async () => {
146147
const { variablesMeta } = await runServerless();
147148
expect(variablesMeta.get('custom\0unsupportedAddress').error.code).to.equal(
148-
'VARIABLE_RESOLUTION_ERROR'
149+
'MISSING_VARIABLE_RESULT'
149150
);
150151
});
151152

@@ -164,4 +165,14 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/param
164165
expect(variablesMeta.get('provider\0timeout')).to.have.property('variables');
165166
expect(variablesMeta.get('provider\0timeout')).to.not.have.property('error');
166167
});
168+
169+
it('should substitute parameter when provided', async () => {
170+
const { configuration } = await runServerless({ cliParameters: ['bar=qux'] });
171+
expect(configuration.custom.variableWithFallback).to.equal('qux');
172+
});
173+
174+
it('should use fallback when parameter is missing', async () => {
175+
const { configuration } = await runServerless();
176+
expect(configuration.custom.variableWithFallback).to.equal('value');
177+
});
167178
});

0 commit comments

Comments
 (0)