{"record":{"id":"e38110e80b4674f9","repo":"clockworklabs/SpacetimeDB","slug":"local-module-schema-inspection-failed","errorCode":null,"errorMessage":"Local module schema inspection failed","messagePattern":"Local module schema inspection failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/schema_extract.rs","lineNumber":154,"sourceCode":"                .kill_on_drop(true);\n            configure_inspector_environment(&mut command);\n            let mut child = command.spawn().context(\"Cannot start local module schema inspection\")?;\n            observation.started(child.id());\n            let mut output = Vec::new();\n            let mut stdout = child\n                .stdout\n                .take()\n                .context(\"Module inspection stdout unavailable\")?\n                .take(MAX_SCHEMA_BYTES + 1);\n            let result = tokio::select! {\n                biased;\n                _ = send.closed() => Err(anyhow::anyhow!(\"Module inspection cancelled\")),\n                result = tokio::time::timeout(deadline, async {\n                    stdout.read_to_end(&mut output).await.context(\"Cannot read local module schema\")?;\n                    ensure!(output.len() as u64 <= MAX_SCHEMA_BYTES, \"Local module schema exceeds output limit\");\n                    let status = child.wait().await.context(\"Cannot reap local module inspector\")?;\n                    observation.reaped(status);\n                    ensure!(status.success(), \"Local module schema inspection failed\");\n                    Ok(())\n                }) => result.unwrap_or_else(|_| Err(anyhow::anyhow!(\"Local module schema inspection timed out\"))),\n            };\n            if result.is_err() {\n                // Queue termination, then retain ownership through positive reaping.\n                let _ = child.start_kill();\n                let status = child\n                    .wait()\n                    .await\n                    .context(\"Cannot reap failed local module inspector\")?;\n                observation.reaped(status);\n            }\n            result?;\n            // Neither parser nor validation diagnostics may echo schema literals.\n            let SerdeWrapper::<RawModuleDef>(raw) = serde_json::from_slice(&output)\n                .map_err(|_| anyhow::anyhow!(\"Local module inspector returned invalid schema data\"))?;\n            let schema =\n                ModuleDef::try_from(raw).map_err(|_| anyhow::anyhow!(\"Local module schema validation failed\"))?;","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/schema_extract.rs#L136-L172","documentation":"After reading the inspector's stdout, the CLI reaps the module inspector subprocess and requires a successful exit status. A non-zero status means the local inspector (the module run for schema extraction) crashed, panicked, or otherwise failed, so its schema cannot be trusted and inspection fails.","triggerScenarios":"`inspect_observed` calls `child.wait()` and the inspector process exits non-zero — e.g. the wasm module panics during initialization, the inspector binary is incompatible with the module, or the module traps while emitting its schema.","commonSituations":"A module whose `__preupload__`/init code panics; running the inspector against a module built for a different ABI/toolchain version; missing runtime dependencies for the inspector subprocess.","solutions":["Run the module locally and fix the panic/trap reported in the inspector's stderr (module init or reducer panics are the usual cause).","Rebuild the module matching the toolchain/ABI the inspector expects (align `spacetimedb` crate and CLI versions).","Check inspector stderr and exit code for missing binaries or runtime issues; install missing dependencies.","Verify with `spacetime publish` to a local server to see whether the module initializes correctly outside the extraction path."],"exampleFix":"// before: module init panics during inspection\n#[spacetimedb::reducer(init)]\nfn init(ctx: &ReducerContext) { panic!(\"oops\"); }\n// after\n#[spacetimedb::reducer(init)]\nfn init(ctx: &ReducerContext) {\n    ctx.db.users.insert(User { id: 0 });\n}","handlingStrategy":"try-catch","validationCode":"// run the module once locally and check it initializes cleanly\nlet status = std::process::Command::new(&inspector_path).arg(&module).status()?;\nif !status.success() { return Err(anyhow!(\"module inspector would fail; fix module init first\")); }","typeGuard":null,"tryCatchPattern":"match inspect_observed(...) {\n    Ok(observation) => use_schema(observation),\n    Err(e) if e.to_string().contains(\"inspection failed\") => {\n        log::error!(\"module inspector exited non-zero: {e}; check module init/panic\");\n        fix_module_and_retry();\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Test that module init/preupload reducers run without panicking before extraction","Keep CLI and spacetimedb crate versions aligned (same module ABI)","Check inspector stderr for traps and missing runtime dependencies"],"tags":["rust","cli","subprocess","wasm"],"backgroundTag":"module-init-failed","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}