Skip to content
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 error messages for invalid property access/calls in GDScript #46241

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Feb 20, 2021

Marking as draft since I haven't had time to test this yet (especially the null check).

The reversed order of the messages now matches Python.

See #46214.

The reversed order of the messages now matches Python.

See godotengine#46214.
@@ -2186,7 +2186,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
} else {
switch (base.builtin_type) {
case Variant::NIL: {
push_error(vformat(R"(Invalid get index "%s" on base Nil)", name), p_identifier);
push_error(vformat(R"(Value of type Nil does not have the attribute "%s".)", name), p_identifier);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have information about what identifier is of type Nil? Or would that be explicit enough from the stacktrace?

Copy link
Contributor

@ThakeeNathees ThakeeNathees Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder why the keyword literal is null and its name is nil. They have different meanings in some other languages (like Objective C, Scala). In general, NULL is 0 or '\0' in ASCII and Nil is emptiness. (I'd like it as null)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this in a GDScript meeting and suggest indeed referring to null directly. Maybe this could be:

Suggested change
push_error(vformat(R"(Value of type Nil does not have the attribute "%s".)", name), p_identifier);
push_error(vformat(R"(Could not get attribute "%s" on a null value.)", name), p_identifier);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or the same phrasing as used in your VM changes to be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or the same phrasing as used in your VM changes to be consistent.

Which changes are you referring to? I may have forgotten something 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the sentence you used for the null case in gdscript_vm.cpp:

err_text = "Tried to access attribute " + v + " on a value that is null.";

@akien-mga akien-mga requested a review from a team February 24, 2021 10:49
@akien-mga
Copy link
Member

Looks good to me from a quick review. Would be nice to change in 3.2 too but will need a dedicated PR.

@Calinou
Copy link
Member Author

Calinou commented Mar 9, 2021

This PR works as expected, but when using an invalid index on array, the wording doesn't make much sense:

image

I'll need to detect whether the type is an array or PackedArray and display a different message in this case. We can also use this opportunity to display the number of elements in the array in the error message 🙂

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me.

Comment on lines +811 to +815
if (!src->is_null()) {
err_text = "Tried to access attribute " + v + " on a value that is null.";
} else {
err_text = "Value of type '" + _get_var_type(src) + "' does not have the attribute " + v + ".";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the condition backwards here?

@reduz
Copy link
Member

reduz commented Jul 29, 2022

I do not think we use the word "attribute" for these things, I would discuss with @vnen what works bet

@akien-mga
Copy link
Member

Superseded by #66948.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants