question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

core: add "getContext" which throws if context doesn't exist

See original GitHub issue

Construct 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:open
  • Created 5 years ago
  • Reactions:7
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
eladbcommented, Nov 11, 2019

still relevant

5reactions
ricardosllmcommented, Jan 8, 2020

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

$ cdk bootstrap aws://<account>/<region>

<project_root>/node_modules/@aws-cdk/aws-route53/lib/hosted-zone.js:77
        if (response.Name.endsWith('.')) {
                          ^

TypeError: Cannot read property 'endsWith' of undefined
at Function.fromLookup (/<project_root>//node_modules/@aws-cdk/aws-route53/lib/hosted-zone.js:77:27)
at new <xxxx> (/<project_root>//static-site.js:21:41)
at new <xxxx> (/<project_root>//index.js:20:9)
at Object.<anonymous> (/<project_root>//index.js:27:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found