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

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

Open
kazimuth opened this issue Feb 13, 2025 · 1 comment
Open

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

kazimuth opened this issue Feb 13, 2025 · 1 comment

Comments

@kazimuth
Copy link
Contributor

kazimuth commented Feb 13, 2025

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...
/// }
/// ```
)
@gefjon
Copy link
Contributor

gefjon commented Feb 14, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants