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 message when trying to call non-@tool function from @tool script #84045

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Oct 27, 2023

Testing project: test_tool_script_function_error.zip

Preview

Before

  res://Node2D.gd:6 - Invalid call. Nonexistent function 'say_hello' in base 'Node (ChildNode.gd)'.

After

 res://Node2D.gd:6 - Invalid call. Nonexistent function 'say_hello' in base 'Node (ChildNode.gd)' ('say_hello' is from a non-@tool script, but is called from @tool script; make the script containing 'say_hello' @tool).

@npip99
Copy link

npip99 commented Nov 21, 2023

The comments in the code say "is likely", but the actual message to the user speaks as a matter of fact.

Is it guaranteed to be that case? The comment shouldn't say "is likely" then. Is it not guaranteed to be that case? The user to the message should say "it may be" or maybe the message should just be "$STANDARD_MESSAGE (function is not in @tool script?)", mimic'ing question-mark "?" bugs for other compilers that theorize what the issue is to the user ("Missing semi-colon?").

@Calinou Calinou force-pushed the tool-script-improve-nonexistent-function-error-message branch from 6cea41d to 4bc4ac4 Compare January 31, 2024 01:41
err_text = _get_call_error(err, "function '" + methodstr + (is_callable ? "" : "' in base '" + basestr) + "'", (const Variant **)argptrs);

String tool_suffix;
if (base->has_method(methodstr)) {
Copy link
Member

@AThousandShips AThousandShips Jan 31, 2024

Choose a reason for hiding this comment

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

I think this is too broad, maybe:

Suggested change
if (base->has_method(methodstr)) {
if (err.error == Callable::CallError::CALL_ERROR_INVALID_METHOD && base->has_method(methodstr)) {

Same below

This part can be reached with other errors, not just not found, like invalid arguments, see for example this output from CI:

Invalid type in function 'expect_typed' in base 'RefCounted (typed_array_pass_basic_to_typed.gd)' ('expect_typed' is from a non-@tool script, but is called from @tool script; make the script containing 'expect_typed' @tool). The array of argument 1 (Array) does not have the same element type as the expected typed array argument.

Also same about the methodstr:

methodstr = String(*argptrs[0]) + " (via TreeItem.call_recursive)";
methodstr = base->operator String() + " (Callable)";
methodstr = String(*argptrs[0]) + " (via call)";

So some more sensitive checking needs to be done IMO

err_text = _get_call_error(err, "function '" + methodstr + "' in base '" + basestr + "'", (const Variant **)argptrs);

String tool_suffix;
if (base->has_method(methodstr)) {
Copy link
Member

Choose a reason for hiding this comment

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

This won't work if it's via call, see above:

methodstr = String(*argptrs[0]) + " (via call)";

@dalexeev
Copy link
Member

@dalexeev
Copy link
Member

#36592 was fixed by #94511. Thanks for the contribution nonetheless!

@dalexeev dalexeev closed this Aug 27, 2024
@dalexeev dalexeev removed this from the 4.x milestone Aug 27, 2024
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.

Improve error message for calling non-tool scripts from tool scripts
4 participants