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

Errors from godot registration functions are not detected #1024

Open
0x53A opened this issue Jan 21, 2025 · 3 comments
Open

Errors from godot registration functions are not detected #1024

0x53A opened this issue Jan 21, 2025 · 3 comments
Labels
c: register Register classes, functions and other symbols to GDScript quality-of-life No new functionality, but improves ergonomics/internals

Comments

@0x53A
Copy link
Contributor

0x53A commented Jan 21, 2025

I stumbled upon this here: #1019 (comment)

See also: godotengine/godot#101870

The issue is that in godot, classdb_register_extension_class_method returns void.

If an error occurs, it just prints an error and returns:

https://github.com/godotengine/godot/blob/1b7b009674e05b566be11a5377b935f5d3d6c0ee/core/object/class_db.cpp#L1879-L1882

	if (type->method_map.has(p_method->get_name())) {
		// overloading not supported
		ERR_FAIL_MSG(vformat("Method already bound '%s::%s'.", p_class, p_method->get_name()));
	}

The macro ERR_FAIL_MSG ultimately calls _err_print_error

which prints to stderr and calls all handlers registered in error_handler_list.

At the least for debug / CI, it would be great to register a handler, and fail CI if an error occurs.

@0x53A
Copy link
Contributor Author

0x53A commented Jan 21, 2025

@0x53A
Copy link
Contributor Author

0x53A commented Jan 21, 2025

My Rust <-> Cpp interop knowledge is limited, but I believe we can't just call that function, without it being explicitly exposed, right? I added a feature request here: godotengine/godot-proposals#11618

@Bromeon
Copy link
Member

Bromeon commented Jan 21, 2025

You're right, the only way to interact with Godot is through gdextension_interface.h.
We additionally have extension_api.json, but this contains just data, no functions.

And indeed, classdb_register_extension_class_method does not return a status code, and I'm not aware of an API to fetch previous errors, either.

An alternative to having errors on Godot side would be:

  • validate invariants (symbol not yet registered) beforehand, through ClassDB API
  • maintain runtime state on godot-rust side and check against that

Both work for simple cases, but may fall apart for more complex validations, and would require Rust to keep up with the exact logic that Godot provides.

@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: register Register classes, functions and other symbols to GDScript labels Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: register Register classes, functions and other symbols to GDScript quality-of-life No new functionality, but improves ergonomics/internals
Projects
None yet
Development

No branches or pull requests

2 participants