(core): Existing Stack fails with CDK "Unexpected token _ in JSON at position 0" #19335
Labels
@aws-cdk/core
Related to core CDK functionality
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p1
What is the problem?
If a stack template was created outside of CDK it may contain errors that are permissible by Cloudformation but are not permissible by
yaml_cfn.deserialize
. When this happens cdk attempts to deserialize the yaml template as JSON 🤷♂️ and will result in an error like this:Unexpected token R in JSON at position 0
during deploy.In my case the existing template had duplicate keys in a resource property resulting in yaml error
YAML parse error, this should never happens, try JSON YAMLSemanticError: Map keys must be unique; "Value" is repeated
. But this error message is not displayed to me.Reproduction Steps
Create a new cdk app with file template
lib/template.yaml
lib/cdk-stack.ts
lib/template.yaml
Deploy template.yaml with
aws cloudformation deploy
:Update template.yaml and remove the duplciate Value key:
lib/template.yaml
Now deploy with cdk with the same stack name
test-cdk-bug
What did you expect to happen?
I should get a yaml error indicating the problem with the template:
YAML parse error, this should never happens, try JSON YAMLSemanticError: Map keys must be unique; "Value" is repeated
What actually happened?
I get a mysterious error that doesn't inform me of the problem:
Unexpected token R in JSON at position 0
CDK CLI Version
2.15.0
Framework Version
No response
Node.js Version
v14.17.0
OS
Fedora
Language
Typescript
Language Version
No response
Other information
The problem is here: https://github.com/aws/aws-cdk/blob/master/packages/aws-cdk/lib/serialize.ts#L18-L19
Why is cdk attempting to deserislize with JSON as the comments suggest should never happen?
Even if this continues the error in the catch should still be logged out to the user.
Related to #15907
The text was updated successfully, but these errors were encountered: