aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(Amazon.CDK.Lib): .NET- JsonSerializationException - Amazon.JSII.JsonModel.Api.Response.ErrorResponseName

Open Chompetto opened this issue 4 years ago • 12 comments

Describe the bug

When upgrading packages I noticed that instead of returning a "normal error" akin to: Amazon.JSII.Runtime.JsiiException: "Cannot find file at foo/bar" It will instead return a generic serialization error for every exception that occurs.

Unhandled exception. Newtonsoft.Json.JsonSerializationException: Error converting value "Error" to type 'Amazon.JSII.JsonModel.Api.Response.ErrorResponseName'. Path 'name'.
 ---> System.ArgumentException: Requested value 'Error' was not found." 

Expected Behavior

Returns a useful error message like previously. Amazon.JSII.Runtime.JsiiException: "Cannot find file at foo/bar"

Current Behavior

Unhandled exception. Newtonsoft.Json.JsonSerializationException: Error converting value "Error" to type 'Amazon.JSII.JsonModel.Api.Response.ErrorResponseName'. Path 'name'. ---> System.ArgumentException: Requested value 'Error' was not found. at Newtonsoft.Json.Utilities.EnumUtils.ParseEnum(Type enumType, NamingStrategy namingStrategy, String value, Boolean disallowNumber) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) --- End of inner exception stack trace --- at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, J at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer) at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType) at Newtonsoft.Json.Linq.JToken.ToObjectT at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson) at Amazon.JSII.Runtime.Services.Client.ReceiveResponseTResponse at Amazon.JSII.Runtime.Services.Client.Create(CreateRequest request) at Amazon.JSII.Runtime.Services.Client.Create(String fullyQualifiedName, Object[] arguments, Override[] overrides, String[] interfaces) at Amazon.JSII.Runtime.Deputy.DeputyBase..ctor(DeputyProps props) at Constructs.Construct..ctor(DeputyProps props) at Amazon.CDK.AWS.Ecr.Assets.DockerImageAsset..ctor(Construct scope, String id, IDockerImageAssetProps props)

Reproduction Steps

Working version(s) I am using.

  • Amazon.CDK.Lib" Version="2.41.0"
  • AWSSDK.Core" Version="3.7.13"

When upgrading to "latest" it will cause the serialization exception.

  • Amazon.CDK.Lib" Version="2.44.0"
  • AWSSDK.Core" Version="3.7.16"

Creating an invalid directory for DockerImageAsset will cause this exception (but any invalid configuration will do) new Amazon.CDK.AWS.Ecr.Assets.DockerImageAsset(this, "DockerImage", new Amazon.CDK.AWS.Ecr.Assets.DockerImageAssetProps { Directory = "" });

Possible Solution

I am guessing a serialization property name or config was updated between these versions listed that is causing an exception when serializing the error response.

Additional Information/Context

No response

CDK CLI Version

2.44.0 (build bf32cb1)

Framework Version

No response

Node.js Version

v16.14.2

OS

Window/Unix

Language

.NET

Language Version

6.0

Other information

No response

Chompetto avatar Oct 05 '22 15:10 Chompetto

I experienced the same error with Amazon.CDK.Lib" Version="2.45.0" and AWSSDK.Core" Version="3.7.13.16" However, I figured out that I was trying to specify a bucket name with some uppercase characters. Once I resolved the issue of the bucket name, the deployment worked.

gbanister avatar Oct 06 '22 17:10 gbanister

I'm having the exact same problem. The error message is useless. Documentation is sparse, to say the least.

ianpowell2017 avatar Oct 17 '22 15:10 ianpowell2017

@ianpowell2017 I would recommend just using the package versions I listed above as a workaround for the time being until they fix their Serialization issues. This way you can at least get usable error messages.

Chompetto avatar Oct 17 '22 15:10 Chompetto

@Chompetto Thanks that has helped enormously. Now I know what I'm missing!

ianpowell2017 avatar Oct 17 '22 16:10 ianpowell2017

I encountered the same thing while using 2.49.

BradKnowles avatar Oct 28 '22 02:10 BradKnowles

Confirming issue still exists in 2.50. Downgrading Amazon.CDK.Lib to 2.41.0, as mentioned above, restores meaningful error messages.

allanwright avatar Nov 16 '22 09:11 allanwright

Confirmed this is still an issue in 2.51.0 as well. This is becoming a blocker as we need to use feature introduced post version 2.45.0

Is the cdk team aware of the issue?

dsdavis4 avatar Nov 18 '22 21:11 dsdavis4

Hey there, we recently made changes to error messages in JSII to add additional information in non-TS languages. I'll take a look at this and try to figure out why it's breaking in Dotnet.

MrArnoldPalmer avatar Nov 18 '22 23:11 MrArnoldPalmer

A possible cause had been mentioned here, but unfortunately that issue has been closed without further investigations due to the root error cause being solved.

This bug currently prevents me from continuing my project. Has anyone figured out a workaround to get the actual error message anyway?

thorbenw avatar Nov 23 '22 15:11 thorbenw

Hi @thorbenw, the workaround I am still using is the one mentioned by @Chompetto, see above

Just downgrade the packages until someone finally fixes this.

ianpowell2017 avatar Nov 23 '22 19:11 ianpowell2017

Fix incoming in JSII https://github.com/aws/jsii/pull/3855

MrArnoldPalmer avatar Nov 24 '22 00:11 MrArnoldPalmer

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Nov 24 '22 15:11 github-actions[bot]