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 the get_node() error message to be more descriptive #46243

Merged

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Feb 20, 2021

  • Mention the origin of the get_node() call.
  • Mention whether the attempted path is absolute or relative.

See #46214.

Test project: test_get_node_error.zip

Preview

Before

ERROR: Node not found: SomeChildNodeDoesntExist.
   at: get_node (scene/main/node.cpp:1405)
ERROR: Node not found: ../SomeChildNodeDoesntExist.
   at: get_node (scene/main/node.cpp:1405)
ERROR: Node not found: /root/ThisDoesntExist.
   at: get_node (scene/main/node.cpp:1405)

After

ERROR: Node not found: "SomeChildNodeDoesntExist" (relative to "/root/Node2D").
   at: get_node (scene/main/node.cpp:1455)
ERROR: Node not found: "../SomeChildNodeDoesntExist" (relative to "/root/Node2D").
   at: get_node (scene/main/node.cpp:1455)
ERROR: Node not found: "/root/ThisDoesntExist" (absolute path attempted from "/root/Node2D").
   at: get_node (scene/main/node.cpp:1450)

@Calinou Calinou requested a review from a team as a code owner February 20, 2021 01:06
@Calinou Calinou added cherrypick:3.x Considered for cherry-picking into a future 3.x release enhancement topic:core labels Feb 20, 2021
@Calinou Calinou added this to the 4.0 milestone Feb 20, 2021
@Calinou Calinou force-pushed the improve-get-node-error-message branch from f4f7f5b to 01dcc63 Compare February 20, 2021 01:07
scene/main/node.cpp Outdated Show resolved Hide resolved
ERR_FAIL_COND_V_MSG(
!node,
nullptr,
vformat(R"(Node not found: "%s" (absolute path attempted from "%s").)", p_path, get_path()));
Copy link
Member

Choose a reason for hiding this comment

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

Is there much point giving this attempted from "%s" info? An absolute path is an absolute path, it doesn't matter where it originates from.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer giving as much context as possible from error messages. While absolute paths behave the same from anywhere, I think the context from the absolute path error message should still remain the same as the relative path error message. Otherwise, this could end up being confusing (an error message being less informative depending of the argument you give to a function).

- Mention the origin of the `get_node()` call.
- Mention whether the attempted path is absolute or relative.

See godotengine#46214.
@Calinou Calinou force-pushed the improve-get-node-error-message branch from 01dcc63 to e6abdc9 Compare February 22, 2021 11:19
@akien-mga akien-mga merged commit 8c5d477 into godotengine:master Feb 22, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.2.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Feb 22, 2021
@Calinou Calinou deleted the improve-get-node-error-message branch March 31, 2021 09:42
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.

3 participants