Skip to content

Validate class registrations against ClassDB - #1664

Merged
Bromeon merged 2 commits into
masterfrom
qol/validate-registrations
Jul 31, 2026
Merged

Validate class registrations against ClassDB#1664
Bromeon merged 2 commits into
masterfrom
qol/validate-registrations

Conversation

@Bromeon

@Bromeon Bromeon commented Jul 23, 2026

Copy link
Copy Markdown
Member

Godot's classdb_register_extension_class* functions return void and only print to stderr on failure, so a rejected class, method, property, signal or constant is silently missing at runtime. The printed Godot error may vary in detail.

New registry::reg_validation module queries ClassDB before each registration and reports a precise error via godot_error! (and in a potential future builder API would allow programmatic check).

In addition, it exits Godot after collecting all errors. Validation runs only under strict safeguards (default in Debug).

#[var] and #[func] are allowed to collide in Godot, but there aren't many use cases, and an explicit #[var(override)] or so might be better. For now warn (no breaking change), will become hard error in v0.6.

Here's a small manual test.
//! Deliberately broken registrations, to see diagnostics of `godot_core::registry::reg_validation`.
//!
//! Diagnostics only go to stderr (not tested). Enable the `mod` in the parent module, run `check.sh itest` and check stderr.
//! Both classes derive `Node`, since `ClassDB` is not reachable at `Core` init level.

use godot::prelude::*;

/// Error: class name already exists. Separate class, as the failed registration aborts before its symbols.
#[derive(GodotClass)]
#[class(init, base = Node, rename = Camera2D)]
struct DemoClassClash {}

/// Errors: duplicate method, property, signal.
/// Warnings: `duplicate`, `owner` and its accessors shadow `Node`.
#[derive(GodotClass)]
#[class(init, base = Node)]
struct DemoSymbolClashes {
    base: Base<Node>,

    #[var]
    same_prop: i32,

    // Explicit accessors: `rename` also renames generated ones, which would already clash at Rust level.
    #[var(get = get_other, set = set_other, rename = same_prop)]
    other_prop: i32,

    #[var]
    owner: i32,
}

#[godot_api]
impl DemoSymbolClashes {
    #[func]
    fn same_name(&self) {}

    #[func(rename = same_name)]
    fn other_name(&self) {}

    #[func]
    fn get_other(&self) -> i32 {
        self.other_prop
    }

    #[func]
    fn set_other(&mut self, value: i32) {
        self.other_prop = value;
    }

    #[func]
    fn duplicate(&self) {}

    #[signal]
    fn ready();
}

Closes #1024.

@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: register Register classes, functions and other symbols to GDScript labels Jul 23, 2026
@Bromeon Bromeon added this to the 0.5.x milestone Jul 23, 2026
@GodotRust

Copy link
Copy Markdown

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1664

@Bromeon
Bromeon force-pushed the qol/validate-registrations branch 7 times, most recently from 2fef30e to 20ef831 Compare July 30, 2026 22:42
@Bromeon
Bromeon force-pushed the qol/validate-registrations branch 4 times, most recently from 48fee02 to 4d0bf16 Compare July 31, 2026 16:50
Bromeon added 2 commits July 31, 2026 19:03
Godot's `classdb_register_extension_class*` functions return void and only print
to stderr on failure. Now, godot-rust queries `ClassDB` before each registration
and reports precise errors via `defer_startup_fatal!`.
@Bromeon
Bromeon force-pushed the qol/validate-registrations branch from 4d0bf16 to e055940 Compare July 31, 2026 17:03
@Bromeon
Bromeon added this pull request to the merge queue Jul 31, 2026
Merged via the queue into master with commit 08edc1f Jul 31, 2026
17 checks passed
@Bromeon
Bromeon deleted the qol/validate-registrations branch July 31, 2026 17:56
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

Successfully merging this pull request may close these issues.

Errors from godot registration functions are not detected

2 participants