{"record":{"id":"a16914914707d96b","repo":"clockworklabs/SpacetimeDB","slug":"either-template-or-lang-must-be-provided-in-no","errorCode":null,"errorMessage":"Either --template or --lang must be provided in non-interactive mode","messagePattern":"Either --template or --lang must be provided in non-interactive mode","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/init.rs","lineNumber":762,"sourceCode":"}\n\nasync fn get_template_config_non_interactive(\n    options: &InitOptions,\n    project_name: String,\n    project_path: PathBuf,\n) -> anyhow::Result<TemplateConfig> {\n    // Check if template is provided\n    if let Some(template_str) = options.template.as_ref() {\n        // Check if it's a builtin template\n        let templates = fetch_templates_list().await?;\n        return create_template_config_from_template_str(project_name, project_path, template_str, &templates);\n    }\n\n    // No template - require at least one language option\n    let server_lang_str = options.lang.clone();\n\n    if server_lang_str.is_none() {\n        anyhow::bail!(\"Either --template or --lang must be provided in non-interactive mode\");\n    }\n\n    Ok(TemplateConfig {\n        project_name,\n        project_path,\n        template_type: TemplateType::Empty,\n        server_lang: parse_server_lang(&server_lang_str)?,\n        client_lang: None,\n        github_repo: None,\n        template_def: None,\n        use_local: true,\n        native_aot: false,\n    })\n}\n\npub fn ensure_empty_directory(_project_name: &str, project_path: &Path, is_server_only: bool) -> anyhow::Result<()> {\n    if project_path.exists() {\n        if !project_path.is_dir() {","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/init.rs#L744-L780","documentation":"Non-interactive init cannot ask questions, so it needs either a template reference or an explicit language to know what to scaffold. With neither `--template` nor `--lang` supplied in non-interactive mode, init aborts before creating anything. (Interactive mode instead shows a language/template picker.) Note that `--template` and `--lang` are mutually exclusive — passing both fails a separate validation.","triggerScenarios":"`spacetime init --non-interactive --project-name my-app` with no `--template` and no `--lang`; CI jobs or Docker builds that assumed interactive defaults; piping stdin to init.","commonSituations":"Automated pipelines written by recording an interactive session; forgetting that non-interactive mode trades prompts for required flags.","solutions":["Add `--lang rust` (or csharp / typescript / cpp)","Add `--template <id>` for a full-stack template, or `--template owner/repo` for a git repo","Run without `--non-interactive` in a real terminal to get the picker"],"exampleFix":"# before\nspacetime init --non-interactive --project-name my-app\n\n# after\nspacetime init --non-interactive --project-name my-app --lang rust","handlingStrategy":"validation","validationCode":"# Enforce the non-interactive contract in the wrapper:\nif [[ \"$NON_INTERACTIVE\" == \"true\" ]]; then\n  [[ -n \"$PROJECT_NAME\" ]] || { echo \"need --project-name\" >&2; exit 2; }\n  [[ -n \"$TEMPLATE\" || -n \"$LANG_ARG\" ]] || { echo \"need --template or --lang\" >&2; exit 2; }\n  [[ -z \"$TEMPLATE\" || -z \"$LANG_ARG\" ]] || { echo \"--template and --lang are mutually exclusive\" >&2; exit 2; }\nfi\nspacetime init --non-interactive --project-name \"$PROJECT_NAME\" ${TEMPLATE:+--template \"$TEMPLATE\"} ${LANG_ARG:+--lang \"$LANG_ARG\"}","typeGuard":null,"tryCatchPattern":"#!/usr/bin/env bash\nif ! spacetime init --non-interactive --project-name \"$PROJECT_NAME\" 2>err.log; then\n  if grep -q \"must be provided in non-interactive mode\" err.log; then\n    echo \"CI misconfig: missing --template/--lang for non-interactive init\" >&2\n    exit 2\n  fi\n  cat err.log >&2; exit 1\nfi","preventionTips":["Encode the non-interactive contract (name + template-or-lang) in a scaffold script or make target","Never pass both --template and --lang — they are mutually exclusive"],"tags":["init","non-interactive","template","missing-flag","ci"],"backgroundTag":"missing-required-flag","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}