Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message when provider does not exist #5964

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/plugins/deploy/deploy.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class Deploy {
this.hooks = { this.hooks = {
'before:deploy:deploy': () => BbPromise.bind(this) 'before:deploy:deploy': () => BbPromise.bind(this)
.then(() => { .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 (this.options.function) {
// If the user has given a function parameter, spawn a function deploy // If the user has given a function parameter, spawn a function deploy
// and terminate execution right afterwards. We did not enter the // and terminate execution right afterwards. We did not enter the
Expand Down
10 changes: 10 additions & 0 deletions lib/plugins/deploy/deploy.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('Deploy', () => {
serverless = new Serverless(); serverless = new Serverless();
options = {}; options = {};
deploy = new Deploy(serverless, options); deploy = new Deploy(serverless, options);
deploy.serverless.providers = { validProvider: true };
deploy.serverless.service.provider.name = 'validProvider';
}); });


describe('#constructor()', () => { describe('#constructor()', () => {
Expand Down Expand Up @@ -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.'
);
});
}); });
}); });