clockworklabs/SpacetimeDB · error · anyhow::Error

Found disallowed print statement(s). These will not be…

Error message

Found {err_count} disallowed print statement(s).
These will not be printed from SpacetimeDB modules.
If you need to print something, use the `log` crate
and the `log::info!` macro instead.

What it means

SpacetimeDB compiles Rust modules to WebAssembly and runs them in its own host, where the standard print macros (println!, print!, eprintln!, eprint!, dbg!) are nonfunctional -- nothing is printed anywhere. Before building, the CLI walks the module's lint directory, scans every .rs file line by line for these macro names, prints each offending file:line, and aborts the build. The `log` crate macros (log::info! etc.) are wired into the host and are the supported way to emit diagnostics.

Solutions

  1. Replace every println!/print!/eprintln!/eprint!/dbg! in module source with log::info!, log::debug!, log::warn! or log::error! from the `log` crate
  2. Make sure `log` is available (it is re-exported by the spacetimedb crate; `use spacetimedb::log;` also works)
  3. Remove or rewrite commented-out code that mentions the macro names, since the scanner matches substrings even in comments
  4. Re-run spacetime build to confirm the lint passes

Example fix

// before
println!("Player {} joined", name);

// after
log::info!("Player {} joined", name);
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
# run before spacetime build
if grep -RnE 'e?print(ln)?!|dbg!' --include='*.rs' src/; then
  echo 'ERROR: print macros are nonfunctional in modules; use log::info!' >&2
  exit 1
fi

Prevention

When it happens

Trigger: Running `spacetime build` or `spacetime publish` on a Rust module whose source files (under the lint dir, typically src/) contain the substring println!, print!, eprintln!, eprint!, or dbg! on any line. The scan is a plain substring match, so even commented-out code or a macro name inside a string literal is flagged.

Common situations: Porting an existing Rust crate (CLI, game server, library) into a SpacetimeDB module; leaving debug prints or a dbg!(x) in helper code during development; commented-out prints still matching the scanner.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/fff625699e60f330. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/tasks/rust.rs:68

                let file = fs::File::open(file.path())?;
                for (idx, line) in io::BufReader::new(file).lines().enumerate() {
                    let line = line?;
                    let line_number = idx + 1;
                    for disallowed in &["println!", "print!", "eprintln!", "eprint!", "dbg!"] {
                        if line.contains(disallowed) {
                            if err_count == 0 {
                                eprintln!("\nDetected nonfunctional print statements:\n");
                            }
                            eprintln!("{printable_path}:{line_number}: {line}");
                            err_count += 1;
                        }
                    }
                }
            }
        }
        if err_count > 0 {
            eprintln!();
            anyhow::bail!(
                "Found {err_count} disallowed print statement(s).\n\
                These will not be printed from SpacetimeDB modules.\n\
                If you need to print something, use the `log` crate\n\
                and the `log::info!` macro instead."
            );
        }
    } else {
        println!(
            "Warning: Skipping checks for nonfunctional print statements.\n\
            If you have used builtin macros for printing, such as println!,\n\
            your logs will not show up."
        );
    }

    let mut args = if let Some(features) = features {
        vec![format!("--features={}", features.to_string_lossy())]
    } else {
        vec![]

View on GitHub (pinned to 6dee26c6ef)