Azure / autorest.csharp

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

Question: how to get more debug information for System.InvalidOperationException: Null constant with non-nullable type string #3213

Open kfcampbell opened 1 year ago

kfcampbell commented 1 year ago

Before asking the question:

Hi! I'm exploring using autorest with a slightly modified version of the GitHub OpenAPI spec (to get rid of some known errors) and attempting to generate a .NET SDK. The configuration file being used is here.

When I run autorest --debug --verbose autorest-config.yaml, I'm seeing the following error after ~25 minutes of processing (our spec is giant and not the most consistent thing):

warning | output-folder path should be an absolute path
debug   | [1400.76 s] csharpproj - END [11.55 s][75 MB]
debug   | [1400.76 s] csharpproj/emitter - START inputs = 1
debug   | [1400.76 s] Emitting 'source-file-csharp' at file:///home/kfcampbell/github/dev/source-generator/generated/Octokit.csproj
debug   | [1400.76 s] csharpproj/emitter - END [0 s][75 MB]
fatal   | System.InvalidOperationException: Null constant with non-nullable type string

   at AutoRest.CSharp.Output.Models.Shared.Constant..ctor(Object value, CSharpType type) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Output\Models\Shared\Constant.cs:line 26
   at AutoRest.CSharp.Output.Builders.BuilderHelpers.ParseConstant(Object value, CSharpType type) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Output\Builders\BuilderHelpers.cs:line 54
   at AutoRest.CSharp.Output.Models.Types.EnumType.BuildValues() in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Output\Models\Types\EnumType.cs:line 91
   at AutoRest.CSharp.Output.Models.Types.EnumType.get_Values() in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Output\Models\Types\EnumType.cs:line 82
   at AutoRest.CSharp.Generation.Writers.ModelWriter.WriteChoiceSchema(CodeWriter writer, EnumType schema) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Generation\Writers\ModelWriter.cs:line 277
   at AutoRest.CSharp.Generation.Writers.ModelWriter.WriteModel(CodeWriter writer, TypeProvider model) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Generation\Writers\ModelWriter.cs:line 26
   at AutoRest.CSharp.AutoRest.Plugins.CSharpGen.ExecuteAsync(Task`1 codeModelTask, Configuration configuration) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\AutoRest\Plugins\CSharpGen.cs:line 50
   at AutoRest.CSharp.AutoRest.Plugins.CSharpGen.Execute(IPluginCommunication autoRest) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\AutoRest\Plugins\CSharpGen.cs:line 134
   at AutoRest.CSharp.AutoRest.Plugins.PluginProcessor.Start(IPluginCommunication autoRest) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\AutoRest\Plugins\PluginProcessor.cs:line 36
fatal   | Process() cancelled due to exception : Plugin csharpgen reported failure. / Error: Plugin csharpgen reported failure.
    at /home/kfcampbell/.autorest/@autorestcore@3.9.4/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:2818:19
    at ScheduleNode (/home/kfcampbell/.autorest/@autorestcore@3.9.4/node_modules/@autorest/core/dist/src_lib_autorest-corets.js:1351:29)
error   |   Error: Plugin csharpgen reported failure.
error   | Autorest completed with an error. If you think the error message is unclear, or is a bug, please declare an issues at https://github.com/Azure/autorest/issues with the error message you are seeing.
debug   | [1401.36 s] Shutting Down.
debug   | [1401.36 s] Exiting.

I'm quite sure that the cause of the error is an issue with our OpenAPI specification. However, the stacktrace and error information output give me no indication of where to troubleshoot further. I don't see a log file output at the specified directory either.

Is there a way I can coax autorest into giving me more information about what's broken and where it is in the specification?

kfcampbell commented 1 year ago

I'm looking to see if I can attach a debugger to the C# generation to see if I can figure out where the OpenAPI spec error it's choking on is. However, the debugging docs are pretty vague about this. Must I set up a Windows VM to use Visual Studio from? Is it possible to set up the debugger from Linux?