core: add "getContext" which throws if context doesn't exist
See original GitHub issueConstruct method getContext() returns undefined when a context key is not defined. Is that the right behavior? I would expect it to fail fast instead of continuing, as I would expect context keys to be “required” in most stacks vs optional. Currently, the behavior of the stack will result in confusing error messages later on, or worse, won’t be caught at all when the stack is synthesized.
Reproduce:
new route53.AliasRecord(this, 'SiteAliasRecord', {
zone,
recordName: this.node.getContext('recordName'),
target: distribution
});
}
“cdk synth” output with missing context key:
$ cdk synth
/XXX/@aws-cdk/aws-route53/lib/records/_util.js:19
if (providedName.endsWith('.')) {
^
TypeError: Cannot read property 'endsWith' of undefined
at Object.determineFullyQualifiedDomainName (/XXX/@aws-cdk/aws-route53/lib/records/_util.js:19:22)
at new AliasRecord (/XXX/@aws-cdk/aws-route53/lib/records/alias.js:14:27)
at new StaticSite (/home/ANT.AMAZON.COM/liguori/code/aws-cdk-examples/typescript/static-site/static-site.js:42:9)
at new MyStaticSiteStack (/home/ANT.AMAZON.COM/liguori/code/aws-cdk-examples/typescript/static-site/index.js:18:9)
at Object.<anonymous> (/home/ANT.AMAZON.COM/liguori/code/aws-cdk-examples/typescript/static-site/index.js:24:1)
at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
at Module.load (internal/modules/cjs/loader.js:626:32)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
at Function.Module._load (internal/modules/cjs/loader.js:558:3)
Subprocess exited with error 1
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:8 (6 by maintainers)
Top Results From Across the Web
java - getContext() doesn't exist - Stack Overflow
method. It states that it cannot find a symbol for that method. So I searched the source and that method in the View...
Read more >[error] Drupal\Component\Plugin\Exception\ContextException
Review and test the patch in #3300682-50: [error] Drupal\Component\Plugin\Exception\ContextException: The context is not a valid context.
Read more >Fragment | Android Developers
The Fragment class can be used many ways to achieve a wide variety of results. In its core, it represents a particular operation...
Read more >VS Code API | Visual Studio Code Extension API
However, when invoking an editor command not all argument types are supported. This is a sample that registers a command handler and adds...
Read more >Using the Eclipse context for RCP applications and plug-ins
To access an existing context you can use dependency injection if the ... getContext(); // add or access objects to and from the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
still relevant
To add more examples I just faced this issue when running
cdk bootstrap
as recommended by another error message while trying to follow this example from aws-sampes