Skip to content

Throw an enhanced exception for node type mismatch #25

@31

Description

@31

The generator currently makes something like this:

[OnReadyGet("Face")] private Spatial _face;
...
if (FacePath != null)
{
	_face = GetNode<global::Godot.Spatial>(FacePath);
}
if (_face == null)
{
	throw new NullReferenceException($"'{((Resource)GetScript()).ResourcePath}' member '_face' is unexpectedly null in '{GetPath()}', '{this}'. Ensure 'FacePath' is set correctly, or set [OnReadyGet(OrNull = true)] to allow null.");
}

The GetNode<global::Godot.Spatial>(FacePath) can throw, and it doesn't include much info. I think it would be useful to use GetNodeOrNull(FacePath) and do the checks on our side, so we can throw a detailed exception if it doesn't work.

A specific situation I want to improve is when the target node is the wrong type. It can be hard to think of this as the root cause, sometimes, and more details would help.

(This is what I was attempting to do with the generated throw, but it only helps in very specific situations.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions