SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

`#[table]` macro has bad error message when invoked inside function

Open kazimuth opened this issue 10 months ago • 2 comments

With a unique column or index. Repro:

fn broken() {
    #[spacetimedb::table(name = users)]
    struct User {
        #[primary_key]
        id: u32,
    }
}

Error:

$ cargo build --target wasm32-unknown-unknown
   Compiling spacetime-module v0.1.0 (F:\clockwork\broken)
error[E0412]: cannot find type `users__TableHandle` in this scope
 --> src\lib.rs:2:33
  |
2 |     #[spacetimedb::table(name = users)]
  |                                 ^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0412`.
error: could not compile `spacetime-module` (lib) due to 1 previous error

This mainly shows up in doctests, which are secretly wrapped in a function scope. Not sure it's possible to get a better error message, but maybe.

(To work around in doctests, just wrap the whole doctest in:

/// ```no_run
/// # mod demo {
/// // doctest code...
/// }
/// ```
)

kazimuth avatar Feb 13 '25 20:02 kazimuth

Is the no_run necessary, or just the mod demo part?

gefjon avatar Feb 14 '25 16:02 gefjon

Is there anything we can do about this?

gefjon avatar Mar 12 '25 20:03 gefjon