Skip to content

Commit

Permalink
chore(cli): improve error message when bootstrap can't find stacks (#…
Browse files Browse the repository at this point in the history
…15538)

The current error message is kind of confusing.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Jul 14, 2021
1 parent cafdd3c commit 28a9ac0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,23 @@ export class CdkToolkit {
* all stacks are implicitly selected.
* @param toolkitStackName the name to be used for the CDK Toolkit stack.
*/
public async bootstrap(environmentSpecs: string[], bootstrapper: Bootstrapper, options: BootstrapEnvironmentOptions): Promise<void> {
public async bootstrap(userEnvironmentSpecs: string[], bootstrapper: Bootstrapper, options: BootstrapEnvironmentOptions): Promise<void> {
// If there is an '--app' argument and an environment looks like a glob, we
// select the environments from the app. Otherwise use what the user said.

// By default glob for everything
environmentSpecs = environmentSpecs.length > 0 ? environmentSpecs : ['**'];
const environmentSpecs = userEnvironmentSpecs.length > 0 ? [...userEnvironmentSpecs] : ['**'];

// Partition into globs and non-globs (this will mutate environmentSpecs).
const globSpecs = partition(environmentSpecs, looksLikeGlob);
if (globSpecs.length > 0 && !this.props.cloudExecutable.hasApp) {
throw new Error(`'${globSpecs}' is not an environment name. Run in app directory to glob or specify an environment name like \'aws://123456789012/us-east-1\'.`);
if (userEnvironmentSpecs.length > 0) {
// User did request this glob
throw new Error(`'${globSpecs}' is not an environment name. Specify an environment name like 'aws://123456789012/us-east-1', or run in a directory with 'cdk.json' to use wildcards.`);
} else {
// User did not request anything
throw new Error('Specify an environment name like \'aws://123456789012/us-east-1\', or run in a directory with \'cdk.json\'.');
}
}

const environments: cxapi.Environment[] = [
Expand Down

0 comments on commit 28a9ac0

Please sign in to comment.