godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Improve C# source generators compile error/warning feedback #6811

Open Sp3ci3s8472 opened 1 year ago

Sp3ci3s8472 commented 1 year ago

Describe the project you are working on

Not really applicable. Just finished migrating my c# project from and got it to compile.

Describe the problem or limitation you are having in your project

After compiling my project in Rider I get the following two warnings: Generator 'ScriptPropertiesGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'NullReferenceException' with message 'Object reference not set to an instance of an object.' Generator 'ScriptSerializationGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'NullReferenceException' with message 'Object reference not set to an instance of an object.'

Since it does not tell me what object or class is throwing the error there is no easy way for me to fix it. Manually trying to find which class it is is not really an option with over 300 files to go over. Unless I compile the sourcegenerators myself and make my own enhanced nuget package? Sadly I have no idea yet on how to do that.

Even though the game seems to run fine when compiled, there is no way for me to make sure it won't crash on some weird thing an hour into play.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

When the sourcegenerators throw a null pointer exception it should at least show which class it tried to generate a source of made it throw the error.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Generator 'ScriptPropertiesGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'NullReferenceException' with message 'Object reference not set to an instance of an object.' This error occured when generating the source for MyNameSpace.MyFancyClass

If this enhancement will not be used often, can it be worked around with a few lines of script?

It will probably always be used if there is a compile error with the source generators.

Is there a reason why this should be core and not an add-on in the asset library?

Better logging of errors is always nice. This should not be optional.

raulsntos commented 1 year ago

These errors are printed by dotnet CLI, not by Godot. If an error occurs when generating source, this is a bug in our source generators. A source generator should not throw an exception, instead it should likely avoid it and report a diagnostic.

I think the stack trace of the exception should be showing up somewhere in your IDE, this may help diagnose what went wrong. Otherwise, without an MRP I don't know what could be causing this issue in Godot's generators.

Sp3ci3s8472 commented 1 year ago

I have looked around for stack traces but I don't know where to look in Rider. Especially since its thrown at build time instead of run time (which are easy to find). If necessary I'll ask the Rider developers for some information?

raulsntos commented 1 year ago

Sorry, I don't use Rider so I don't know. But since you mention your issue is with ScriptPropertiesGenerator and ScriptSerializationGenerator, maybe you are hitting this issue:

Sp3ci3s8472 commented 1 year ago

I think you are right since I'm overriding virtual properties, nice catch! I'm not exporting them though. I'll have a look probably tomorrow and if that indeed solves the warning. We might link these git issues or I don't know the correct procedure? Because it still would be nice to have some more feedback what thing is generating the errors in the first place.

Sp3ci3s8472 commented 1 year ago

A bit later than I hoped, but I can confirm that the issue is indeed: https://github.com/godotengine/godot/issues/71102