{"record":{"id":"70279a831a69bf12","repo":"clockworklabs/SpacetimeDB","slug":"template-definition-missing","errorCode":null,"errorMessage":"Template definition missing","messagePattern":"Template definition missing","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/init.rs","lineNumber":1382,"sourceCode":"\n    // Install AI assistant rules for multiple editors/tools\n    install_ai_rules(config, project_path)?;\n\n    println!(\"{}\", \"Project initialized successfully!\".green());\n\n    Ok(())\n}\n\nfn init_builtin(\n    config: &TemplateConfig,\n    project_path: &Path,\n    is_server_only: bool,\n    dotnet_major: Option<u8>,\n) -> anyhow::Result<()> {\n    let template_def = config\n        .template_def\n        .as_ref()\n        .ok_or_else(|| anyhow::anyhow!(\"Template definition missing\"))?;\n\n    let template_files = embedded::get_template_files();\n\n    if !is_server_only {\n        println!(\n            \"Setting up client ({})...\",\n            config.client_lang.map(|l| l.as_str()).unwrap_or(\"none\")\n        );\n        let client_source = &template_def.client_source;\n        if let Some(files) = template_files.get(client_source.as_str()) {\n            copy_embedded_files(files, project_path)?;\n        } else {\n            anyhow::bail!(\"Client template not found: {}\", client_source);\n        }\n\n        // Update client name\n        match config.client_lang {\n            Some(ClientLanguage::TypeScript) => {","sourceCodeStart":1364,"sourceCodeEnd":1400,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/fdd647dfac506d0967cc4492e9fce380706c94cb/crates/cli/src/subcommands/init.rs#L1364-L1400","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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>`"],"exampleFix":"# before\nspacetime init --template <builtin-id>   # hits 'Template definition missing'\n# after\nspacetime init --template clockworklabs/quickstart-csharp   # GitHub path skips init_builtin","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for i in 1 2; do spacetime init \"$@\" && exit 0; done\nspacetime init --template clockworklabs/quickstart-csharp   # GitHub fallback","preventionTips":["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"],"tags":["cli","init","templates","internal-invariant"],"backgroundTag":"template-definition-missing","analyzedSha":"fdd647dfac506d0967cc4492e9fce380706c94cb","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}