31 / GodotOnReady

A C# Source Generator that adds convenient onready-like features to your C# scripts in Godot Mono (3.x) without any reflection.
https://www.nuget.org/packages/GodotOnReady
MIT License
123 stars 13 forks source link

Generate a better exception message when exported NodePath is null #15

Closed 31 closed 3 years ago

31 commented 3 years ago

Godot shows a generic exception when the node path isn't assigned:

Unhandled Exception:
System.NullReferenceException: The instance of type NodePath is null.
  at Godot.NodePath.GetPtr (Godot.NodePath instance) [0x00009] in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs:15
  at Godot.Node.GetNode (Godot.NodePath path) [0x00001] in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Node.cs:617
  at Godot.Node.GetNode[T] (Godot.NodePath path) [0x00001] in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs:7
  at MyThing._Ready () [0x00013] in D:\proj\MyThing\src\GodotOnReady.Generator\GodotOnReady.Generator.GodotOnReadySourceGenerator\Partial__MyThing.cs:20

The ready method should detect null and throw an exception that includes script name, node name/path, and field/prop name.