generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 59
feat(cli): can ignore errors and return dummy value in CloudControl API context provider #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
70d7a4c
feat(cli): can ignore errors and return dummy value in cc api context…
go-to-k 08b4b12
method name
go-to-k 2090861
wip
go-to-k ffc040e
call getDummyValueIfErrorIgnored in findResources
go-to-k b69d69b
fix docs
go-to-k 256059a
change CcApiContextQuery interface and modify tests
go-to-k b54e689
rm unused import
go-to-k 74e9aa0
Merge branch 'main' into cc-api-dummy
rix0rrr 0262d51
modify by review
go-to-k bb905c6
modify a test
go-to-k c315497
change getDummyObject
go-to-k 407cdb2
change description of dummyValue
go-to-k 8d9d94c
getDummyObject to getDummyObjects
go-to-k 1a933f0
rm await
go-to-k 3218de7
Merge branch 'main' into cc-api-dummy
go-to-k 4ea2594
revert property name to ignoreErrorOnMissingContext
go-to-k 52d95ab
Refactor to combine code paths a bit more, and remove tests I don't w…
rix0rrr ae199f9
Some eslint work
rix0rrr 9ae446a
Oops, version should be 42
rix0rrr 195aad1
Update version.json
rix0rrr 0d1cd51
Build update
rix0rrr 7c86967
Merge branch 'main' into cc-api-dummy
rix0rrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this behavior be in a
try/catchingetValue()? It seems duplicated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: let's decide what a good error protocol would be here. I'm not convinced that return a single dummy object (which a caller has to supply a value for, and then has to test for that value... and it needs to be different from the default dummy object) is the best protocol.
Also; context provider return values are usually cached. Do we really want "not found" dummy values to be cached? (I.e., if they notice and create the resource after the first synth, we will still behave as if the resource doesn't exist).
Is that behavior going to match expected user behavior?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly. Decided to use try/catch in
findResourcesso that the following errors are not ignoredffc040e
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. However, throwing an error will cause the CLI to exit, so it must be returned with the normal return type (
{[key: string]: any} []). The normal return value is also constructed and returned based on the following function.Would it then be better to return an array of objects such as
[{ Identifier: ‘dummy-id’ }]or[{ ErrorIgnored: true }](or an empty object...)?I believe this is a matter on the cdk-lib side. The command for clearing the context can avoid that behaviour, but if we are concerned about the hassle, we could add a process on the cdk-lib side that also reports a missingContext and doesn't cache it if a dummy value is stored.
https://github.com/aws/aws-cdk/blob/v2.183.0/packages/aws-cdk-lib/core/lib/context-provider.ts#L108-L131
Either way, as cdk-cli, if we don't create a mechanism to ignore the error, the CDK CLI will terminate with an error when the resource is not found. This means that it will be difficult to fulfil the CDK use case of "use an existing resource if it is available, otherwise create it", so I think this PR should make sense. The existing SSM and KMS providers already support it, so it would be natural to do it in the CC API as well.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, I came up with the idea of throwing an error with a message indicating something "ignored" in the CLI and not doing
Annotations.addError(here) if the message is detected on the cdk-lib side. However, this may result in less clean code as it handles the error message and may be a bit confusing as it goes against the meaning of the property nameignoreErrorOnMissingContext...Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but if a custom class like
class IgnoredContextProviderError extends ContextProviderError {}is created and it is thrown ingetValue(findResources) ifignoreErrorOnMissingContextis true, and this code is changed with handling the error (if (e instanceof IgnoredContextProviderError) ...), perhaps it could be handled more naturally... (Even so, changes will still need to be made on the cdk-lib side, but...)For example:
findResourcesof packages/aws-cdk/lib/context-providers/cc-api-provider.tsprovideContextValuesof packages/aws-cdk/lib/context-providers/index.tsThis way, the error protocol does not depend on dummy values in cdk-cli, and it may be possible to avoid caching them in the context (although it may require a few changes on the lib side, and if a new key should be added, on the cxapi side too).
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the volume of comments (I've given it a lot of thought).
Either way, I am willing to act once I have your opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had sort of missed how this error ignoring protocol, where we record
dummyValueas the "official response" had already been implemented in aws/aws-cdk#31415 before, and is being used in 2 other context providers already.I still can't say I'm happy about it, but there's precedent so we might as well do the same thing as these other context providers until we decide that all of their behaviors should be changed!
I've documented my understanding of these flags here: aws/aws-cdk#33875. If you think this is accurate, then we should just be doing what the documented protocol says.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read and thought it is accurate. So I have changed to use
ignoreFailedLookupinstead ofignoreErrorOnMissingContext.0262d51
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that the property called by cdk-lib is still
ignoreErrorOnMissingContext.https://github.com/aws/aws-cdk/pull/33875/files#diff-0d73bed6d4cd92ebf3292b51185a26f6e85c3e9cf6eb37c28bfc48a457600876R169-R172
So I changed the property name back to
ignoreErrorOnMissingContext.4ea2594