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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,15 @@ Node *Node::get_node_or_null(const NodePath &p_path) const {

Node *Node::get_node(const NodePath &p_path) const {
Node *node = get_node_or_null(p_path);
ERR_FAIL_COND_V_MSG(!node, nullptr, "Node not found: " + p_path + ".");

if (p_path.is_absolute()) {
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).

} else {
ERR_FAIL_COND_V_MSG(!node, nullptr,
vformat(R"(Node not found: "%s" (relative to "%s").)", p_path, get_path()));
}

return node;
}

Expand Down