clockworklabs / clockworklabs/SpacetimeDB

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

Open
#2,260 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

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...
/// }
/// ```
)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown #[spacetimedb::table] example using cargo build --target wasm32-unknown-unknown. Start by tracing the table macro’s behavior in function scope and compare it with module scope and doctest wrapping. Done means providing a more useful diagnostic, or establishing and documenting that the current limitation cannot be improved.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.