clockworklabs/SpacetimeDB · error · anyhow::Error
Template definition missing
Error message
Template definition missing
What it means
init_builtin scaffolds a project from an embedded built-in template and requires config.template_def (the parsed TemplateDefinition fetched from the template registry). TemplateConfig construction normally sets template_def: Some(...) only for built-in templates (init.rs:379, 923) and None for GitHub/custom paths — so TemplateType::Builtin reaching init_builtin with template_def None violates the constructor's invariant and this guard fires.
Solutions
- Retry `spacetime init` (transient registry fetch/parse issues resolve on a clean fetch)
- Update the CLI so embedded template handling matches the current registry schema
- Work around by cloning a template from GitHub instead: `spacetime init --template <owner>/<repo>`
Example fix
# before spacetime init --template <builtin-id> # hits 'Template definition missing' # after spacetime init --template clockworklabs/quickstart-csharp # GitHub path skips init_builtin
Defensive patterns
Strategy: retry
Try / catch
for i in 1 2; do spacetime init "$@" && exit 0; done spacetime init --template clockworklabs/quickstart-csharp # GitHub fallback
Prevention
- Pin CLI versions used for scaffolding in CI to avoid registry/embedded-template schema drift
- Fall back to GitHub template paths (`owner/repo`) when builtin scaffolding fails
- Re-run init on a clean directory so partially scaffolded state doesn't accumulate
When it happens
Trigger: A code path that classifies a template as Builtin but fails to attach its definition — e.g. a template id resolved against the fetched registry on one code path but classified Builtin on another, or a registry entry whose definition failed to parse while the id still matched. Not triggerable by ordinary flag combinations in healthy builds.
Common situations: Version skew between the CLI's embedded template handling and the remote template registry format; partially failed template-list fetches where ids survive but definitions don't; custom/enterprise template registries returning unexpected shapes.
Related errors
- No templates found for selected language
- Project initialization did not create spacetimedb directory
- Unknown client language
- Unknown server language
- Aborted.
AI-assisted analysis of clockworklabs/SpacetimeDB@fdd647dfac (2026-08-20).
Data as JSON: /api/errors/70279a831a69bf12.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/subcommands/init.rs:1382
// Install AI assistant rules for multiple editors/tools
install_ai_rules(config, project_path)?;
println!("{}", "Project initialized successfully!".green());
Ok(())
}
fn init_builtin(
config: &TemplateConfig,
project_path: &Path,
is_server_only: bool,
dotnet_major: Option<u8>,
) -> anyhow::Result<()> {
let template_def = config
.template_def
.as_ref()
.ok_or_else(|| anyhow::anyhow!("Template definition missing"))?;
let template_files = embedded::get_template_files();
if !is_server_only {
println!(
"Setting up client ({})...",
config.client_lang.map(|l| l.as_str()).unwrap_or("none")
);
let client_source = &template_def.client_source;
if let Some(files) = template_files.get(client_source.as_str()) {
copy_embedded_files(files, project_path)?;
} else {
anyhow::bail!("Client template not found: {}", client_source);
}
// Update client name
match config.client_lang {
Some(ClientLanguage::TypeScript) => {View on GitHub (pinned to fdd647dfac)