From 22eec9537e65d22994ea5d7cda2a248eb398a4b5 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 30 Jun 2019 21:17:43 +0300 Subject: [PATCH 1/3] fix(core): improve context providers error message for env-agnostic stacks Following up on #2922: improve the error message emitted when trying to read context from an environment-agnostic stack by calling out CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION as a way to inherit environment information from the CLI. Fixes #3078 Fixes #3120 Fixes #3130 --- packages/@aws-cdk/core/lib/context-provider.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/lib/context-provider.ts b/packages/@aws-cdk/core/lib/context-provider.ts index 4353218580111..898a47ed51a50 100644 --- a/packages/@aws-cdk/core/lib/context-provider.ts +++ b/packages/@aws-cdk/core/lib/context-provider.ts @@ -71,7 +71,10 @@ export class ContextProvider { const stack = Stack.of(scope); if (Token.isUnresolved(stack.account) || Token.isUnresolved(stack.region)) { - throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region are not specified at the stack level`); + throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region ` + + `are not specified at the stack level. Either configure "env" with explicit account and region when ` + `you define your stack, or use the environment variables "CDK_DEFAULT_ACCOUNT" and "CDK_DEFAULT_REGION" ` + + `to inherit environment information from the CLI (not recommended for production stacks)`); } const { key, props } = this.getKey(scope, options); From 5bec647e32f0cdccb350aee91007829eeab8c634 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 30 Jun 2019 21:48:16 +0300 Subject: [PATCH 2/3] missing "+ --- packages/@aws-cdk/core/lib/context-provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/lib/context-provider.ts b/packages/@aws-cdk/core/lib/context-provider.ts index 898a47ed51a50..d0b132f31e3f1 100644 --- a/packages/@aws-cdk/core/lib/context-provider.ts +++ b/packages/@aws-cdk/core/lib/context-provider.ts @@ -72,7 +72,7 @@ export class ContextProvider { if (Token.isUnresolved(stack.account) || Token.isUnresolved(stack.region)) { throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region ` + - `are not specified at the stack level. Either configure "env" with explicit account and region when ` + `are not specified at the stack level. Either configure "env" with explicit account and region when ` + `you define your stack, or use the environment variables "CDK_DEFAULT_ACCOUNT" and "CDK_DEFAULT_REGION" ` + `to inherit environment information from the CLI (not recommended for production stacks)`); } From 0c260285d7353df29876726c5aec20ec6e56d132 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 30 Jun 2019 23:05:08 +0300 Subject: [PATCH 3/3] remove trailing whitespace --- packages/@aws-cdk/core/lib/context-provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/lib/context-provider.ts b/packages/@aws-cdk/core/lib/context-provider.ts index d0b132f31e3f1..cd211e02638e8 100644 --- a/packages/@aws-cdk/core/lib/context-provider.ts +++ b/packages/@aws-cdk/core/lib/context-provider.ts @@ -71,7 +71,7 @@ export class ContextProvider { const stack = Stack.of(scope); if (Token.isUnresolved(stack.account) || Token.isUnresolved(stack.region)) { - throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region ` + + throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region ` + `are not specified at the stack level. Either configure "env" with explicit account and region when ` + `you define your stack, or use the environment variables "CDK_DEFAULT_ACCOUNT" and "CDK_DEFAULT_REGION" ` + `to inherit environment information from the CLI (not recommended for production stacks)`);