-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve wording for "Invalid get index" error #46214
Comments
The reversed order of the messages now matches Python. See godotengine#46214.
This is definitely a good idea as per the advice of #42719 🙂 |
Wow, you just went ahead and did something even better. Many thanks, LGTM! 😀 |
- Mention the origin of the `get_node()` call. - Mention whether the attempted path is absolute or relative. See godotengine#46214.
Godot version:
3.2, but the same wording is used in
master
.Issue description:
I lurk in the Godot subreddit, and one of the (if not the) errors that beginners encounter most frequently is of the form "Invalid get index 'X' (on base 'Y')". Now, I'm an experienced programmer with many languages, but without any context this message would make little sense to me either! I think everyone would be helped if we could make this error clearer.
First improvement:
Simply rephrase the error as
Value of type 'Y' does not have attribute 'X'
. This is similar to Python. It also puts the arguments in the same order as they appear in the code.If the GDScript interpreter can tell whether it's a property access or method call, it could be specified as
Value of type 'Y' does not have (property|method) 'X'
.Second improvement:
Add a dedicated message for the common case of
Y == null
, such asTried to access attribute 'X' on a value that is null
.Again, if we know the type of access, say
access property
orcall method
instead.Third improvement: (moonshot)
This would be icing on the cake, but might be taking it too far. One of the most frequent causes of X being null is that a particular node was not found. So if X is either
$node
or aget_node
call with a literal path, the error could be reported asNode 'N' not found relative to 'P'
, whereN
is the NodePath of the node that doesn't exist, andP
is the NodePath ofself
.I'd be happy to write PRs for this if the Godot devs agree. Particularly interested in input from GDScript guru @vnen of course!
The text was updated successfully, but these errors were encountered: