{"record":{"id":"3c0f56de6012e90e","repo":"FuelLabs/sway","slug":"failed-to-find-a-template-in","errorCode":null,"errorMessage":"failed to find a template `{}` in {}","messagePattern":"failed to find a template `(.+?)` in (.+?)","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc/src/ops/forc_template.rs","lineNumber":50,"sourceCode":"    let fetch_id = source::fetch_id(current_dir, fetch_ts);\n\n    println_action_green(\"Resolving\", &format!(\"the HEAD of {}\", source.repo));\n    let git_source = source::git::pin(fetch_id, &local_repo_name, source)?;\n\n    let repo_path = source::git::commit_path(\n        &local_repo_name,\n        &git_source.source.repo,\n        &git_source.commit_hash,\n    );\n    if !repo_path.exists() {\n        println_action_green(\"Fetching\", git_source.to_string().as_str());\n        source::git::fetch(fetch_id, &local_repo_name, &git_source)?;\n    }\n\n    let from_path = match command.template_name {\n        Some(ref template_name) => manifest::find_dir_within(&repo_path, template_name)\n            .ok_or_else(|| {\n                anyhow!(\n                    \"failed to find a template `{}` in {}\",\n                    template_name,\n                    command.url\n                )\n            })?,\n        None => {\n            let manifest_path = repo_path.join(constants::MANIFEST_FILE_NAME);\n            if PackageManifest::from_file(manifest_path).is_err() {\n                anyhow::bail!(\"failed to find a template in {}\", command.url);\n            }\n            repo_path\n        }\n    };\n\n    // Create the target dir\n    let target_dir = current_dir.join(&command.project_name);\n\n    println_action_green(","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc/src/ops/forc_template.rs#L32-L68","documentation":"forc template first fetches the template repo, then for a named template calls manifest::find_dir_within(&repo_path, template_name) to locate the directory; None (no directory with that name anywhere under the fetched repo) becomes \"failed to find a template `<name>` in <url>\".","triggerScenarios":"`forc template <url> <project-name> --template-name <name>` where <name> does not match any directory in the repository (typo, wrong case, template removed/renamed upstream).","commonSituations":"Templates listed in a README drifting from the repo contents, renaming of templates between template-repo versions, or users guessing template names for a multi-template repo.","solutions":["List the fetched repo's directories (the cached checkout under the forc template cache) or browse the repo to get the exact template directory name","Check spelling and case — find_dir_within matches the directory name exactly","If the template should be at the repo root with no subdirectory, omit --template-name"],"exampleFix":"# before\nforc template https://github.com/example/templates myapp --template-name counterr\n\n# after\nforc template https://github.com/example/templates myapp --template-name counter","handlingStrategy":"validation","validationCode":"// Before running forc template, verify the template dir exists in a local clone.\nlet template_dir = format!(\"{clone_dir}/{template_name}\");\nif !std::path::Path::new(&template_dir).is_dir() {\n    anyhow::bail!(\"template '{template_name}' not found under {clone_dir}; check exact name/case\");\n}","typeGuard":"fn valid_template_name(name: &str) -> bool {\n    !name.is_empty() && !name.contains('/') && !name.contains(\"..\")\n}","tryCatchPattern":"match run_forc_template(url, project, Some(&name)) {\n    Ok(()) => Ok(()),\n    Err(e) if e.to_string().contains(\"failed to find a template\") => {\n        anyhow::bail!(\"list available templates in {url} and retry with the exact directory name\")\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Copy template names verbatim from the repo's docs/README (they are directory names, case-sensitive)","For CI scaffolding, pin a template repo commit so renames upstream cannot break you"],"tags":["forc","template","repo","cli-args"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}