Merge pull request #5964 from Xenonym/enhancement/non-existent-provider-error

Add error message when provider does not exist
This commit is contained in:
Philipp Muens 2019-03-29 09:32:56 +01:00 committed by GitHub
commit 467cdf84a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -105,6 +105,11 @@ class Deploy {
this.hooks = {
'before:deploy:deploy': () => BbPromise.bind(this)
.then(() => {
const provider = this.serverless.service.provider.name;
if (!this.serverless.getProvider(provider)) {
const errorMessage = `The specified provider "${provider}" does not exist.`;
return BbPromise.reject(new this.serverless.classes.Error(errorMessage));
}
if (this.options.function) {
// If the user has given a function parameter, spawn a function deploy
// and terminate execution right afterwards. We did not enter the

View File

@ -20,6 +20,8 @@ describe('Deploy', () => {
serverless = new Serverless();
options = {};
deploy = new Deploy(serverless, options);
deploy.serverless.providers = { validProvider: true };
deploy.serverless.service.provider.name = 'validProvider';
});
describe('#constructor()', () => {
@ -90,5 +92,13 @@ describe('Deploy', () => {
),
]));
});
it('should throw an error if provider does not exist', () => {
deploy.serverless.service.provider.name = 'nonExistentProvider';
return expect(deploy.hooks['before:deploy:deploy']()).to.be.rejectedWith(
'The specified provider "nonExistentProvider" does not exist.'
);
});
});
});