Skip to content

Commit

Permalink
fix(CLI): Ensure help output with missing provider.name
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Apr 6, 2021
1 parent e91f164 commit dae9058
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/configuration/resolve-provider-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
const ensureString = require('type/string/ensure');
const isObject = require('type/object/is');
const ServerlessError = require('../serverless-error');
const resolveCliInput = require('../cli/resolve-input');

module.exports = (configuration) => {
return ensureString(
isObject(configuration.provider) ? configuration.provider.name : configuration.provider,
{
Error: ServerlessError,
errorMessage: 'Invalid service configuration: "provider.name" property is missing',
}
);
try {
return ensureString(
isObject(configuration.provider) ? configuration.provider.name : configuration.provider,
{
Error: ServerlessError,
errorMessage: 'Invalid service configuration: "provider.name" property is missing',
}
);
} catch (error) {
if (resolveCliInput().isHelpRequest) return null;
throw error;
}
};
12 changes: 12 additions & 0 deletions scripts/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ const processSpanPromise = (async () => {

if (isPropertyResolved(variablesMeta, 'provider\0name')) {
providerName = resolveProviderName(configuration);
if (providerName == null) {
variablesMeta = null;
return;
}
}
if (!commandSchema && providerName === 'aws') {
// If command was not recognized in first resolution phase
Expand Down Expand Up @@ -224,6 +228,10 @@ const processSpanPromise = (async () => {

if (!providerName && isPropertyResolved(variablesMeta, 'provider\0name')) {
providerName = resolveProviderName(configuration);
if (providerName == null) {
variablesMeta = null;
return;
}
if (!commandSchema && providerName === 'aws') {
// If command was not recognized in previous resolution phases
// Parse args again also against schemas of commands which work in context of an AWS
Expand Down Expand Up @@ -296,6 +304,10 @@ const processSpanPromise = (async () => {
if (!providerName) {
if (!ensureResolvedProperty('provider\0name')) return;
providerName = resolveProviderName(configuration);
if (providerName == null) {
variablesMeta = null;
return;
}
if (!commandSchema && providerName === 'aws') {
resolveInput.clear();
({ command, commands, options, isHelpRequest, commandSchema } = resolveInput(
Expand Down

0 comments on commit dae9058

Please sign in to comment.