Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
141 stars 161 forks source link

[defect] codegen gen crash : null value in list is not allowed error #4898

Open chunyu3 opened 1 week ago

chunyu3 commented 1 week ago

Typespec tsp, and emitter "2021-10" API Version

Compiling tsp using @azure-tools/typespec-csharp... Unhandled exception. System.Text.Json.JsonException: null value in list is not allowed at AutoRest.CSharp.Common.Input.Utf8JsonReaderExtensions.TryReadWithConverter[T](Utf8JsonReader& reader, String propertyName, JsonSerializerOptions options, IReadOnlyList1& value) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Input\Utf8JsonReaderExtensions.cs:line 154 at AutoRest.CSharp.Common.Input.TypeSpecInputOperationConverter.CreateOperation(Utf8JsonReader& reader, String id, String name, JsonSerializerOptions options, ReferenceResolver resolver) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Input\InputTypes\Serialization\TypeSpecInputOperationConverter.cs:line 54 at AutoRest.CSharp.Common.Input.TypeSpecInputOperationConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Input\InputTypes\Serialization\TypeSpecInputOperationConverter.cs:line 24 at AutoRest.CSharp.Common.Input.Utf8JsonReaderExtensions.ReadWithConverter[T](Utf8JsonReader& reader, JsonSerializerOptions options) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Input\Utf8JsonReaderExtensions.cs:line 163 at AutoRest.CSharp.Common.Input.Utf8JsonReaderExtensions.TryReadWithConverter[T](Utf8JsonReader& reader, String propertyName, JsonSerializerOptions options, IReadOnlyList1& value) in D:\a_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Input\Utf8JsonReaderExtensions.cs:line 153 at AutoRest.CSharp.Common.Input.TypeSpecInputClientConverter.CreateInputClient(Utf8JsonReader& reader, String id, JsonSerializerOptions options, ReferenceResolver resolver) in D:\a_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Input\InputTypes\Serialization\TypeSpecInputClientConverter.cs:line 38 at AutoRest.CSharp.Common.Input.TypeSpecInputClientConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) in D:\a_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Input\InputTypes\Serialization\TypeSpecInputClientConverter.cs:line 22 at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonCollectionConverter2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable1 actualByteCount) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 json, JsonTypeInfo jsonTypeInfo) at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options) at AutoRest.CSharp.Common.Input.TypeSpecSerialization.Deserialize(String json) in D:\a_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Input\InputTypes\Serialization\TypeSpecSerialization.cs:line 42 at AutoRest.CSharp.AutoRest.Communication.StandaloneGeneratorRunner.RunAsync(CommandLineOptions options) in D:\a_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\AutoRest\Communication\StandaloneGeneratorRunner.cs:line 50 at AutoRest.CSharp.Program.Run(CommandLineOptions options) in D:\a_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 47 at AutoRest.CSharp.Program.<>c.<

b__2_0>d.MoveNext() in D:\a_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 29 --- End of stack trace from previous location --- at AutoRest.CSharp.Program.Main(String[] args) in D:\a_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 26 at AutoRest.CSharp.Program.
(String[] args) ExternalError: Emitter "@azure-tools/typespec-csharp" crashed! This is a bug. Please file an issue at https://github.com/Azure/autorest.csharp/issues

Error: Command failed: dotnet --roll-forward Major C:/Users/mredding/source/repos/azure-sdk-for-net/sdk/schemaregistry/Azure.Data.SchemaRegistry/TempTypeSpecFiles/SchemaRegistry/node_modules/@autorest/csharp/AutoRest.CSharp.dll --project-path C:/Users/mredding/source/repos/azure-sdk-for-net/sdk/schemaregistry/Azure.Data.SchemaRegistry --clear-output-folder true at checkExecSyncError (node:child_process:885:11) at execSync (node:child_process:957:15) at Object.$onEmit [as emitFunction] (file:///C:/Users/mredding/source/repos/azure-sdk-for-net/sdk/schemaregistry/Azure.Data.SchemaRegistry/TempTypeSpecFiles/SchemaRegistry/node_modules/@azure-tools/typespec-csharp/dist/src/emitter.js:106:21) at async runEmitter (file:///C:/Users/mredding/source/repos/azure-sdk-for-net/sdk/schemaregistry/Azure.Data.SchemaRegistry/TempTypeSpecFiles/SchemaRegistry/node_modules/@typespec/compiler/dist/src/core/program.js:452:13) at async compile (file:///C:/Users/mredding/source/repos/azure-sdk-for-net/sdk/schemaregistry/Azure.Data.SchemaRegistry/TempTypeSpecFiles/SchemaRegistry/node_modules/@typespec/compiler/dist/src/core/program.js:132:9) at async compileTsp (file:///C:/Users/mredding/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/typespec.js:78:21) at async generate (file:///C:/Users/mredding/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:196:5) at async main (file:///C:/Users/mredding/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:296:13)


Library Version 0.2.0-beta.20240703.5 TypeSpec Compiler Version 0.57.0

chunyu3 commented 1 week ago

root cause: When emit api for 2021-10, the content-type value union SchemaContentTypeValues will be parsed as an array with Null value which is not valid. We need to investigate in tcgc for this

chunyu3 commented 1 week ago

relate with https://github.com/Azure/typespec-azure/issues/1134