{"record":{"id":"df737447e91e189b","repo":"FuelLabs/sway","slug":"failed-to-find-a-template-in-df7374","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":59,"sourceCode":"    );\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(\n        \"Creating\",\n        &format!(\"{} from template\", &command.project_name),\n    );\n    // Copy contents from template to target dir\n    copy_template_to_target(&from_path, &target_dir)?;\n\n    // Edit forc.toml\n    edit_forc_toml(&target_dir, &command.project_name, &whoami::realname())?;\n    if target_dir.join(\"test\").exists() {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc/src/ops/forc_template.rs#L41-L77","documentation":"When `forc template <url> <project-name>` is invoked without --template-name, the whole fetched repo root must itself be a forc package: PackageManifest::from_file(repo_path/Forc.toml) is attempted and .is_err() triggers this bail. It means neither a template name was given nor a root Forc.toml exists.","triggerScenarios":"Cloning a multi-template repository (templates in subdirectories, no manifest at the repo root) without passing --template-name.","commonSituations":"Users pointing at template collections where the root only has a README, or expecting forc to auto-detect the sole template directory, which it does not.","solutions":["Add --template-name pointing at the subdirectory that contains the Forc.toml","Verify with the repo's docs which subdirectory is the intended template","If you own the repo, add a root Forc.toml for the default template"],"exampleFix":"# before\nforc template https://github.com/example/templates myapp\n\n# after\nforc template https://github.com/example/templates myapp --template-name counter","handlingStrategy":"validation","validationCode":"// A repo works without --template-name only if Forc.toml sits at its root.\nif !std::path::Path::new(&format!(\"{repo_root}/Forc.toml\")).is_file() {\n    anyhow::bail!(\"repo has no root Forc.toml; pass --template-name pointing at the template subdir\");\n}","typeGuard":"fn repo_is_root_package(root: &Path) -> bool {\n    root.join(\"Forc.toml\").is_file()\n}","tryCatchPattern":"match run_forc_template(url, project, None) {\n    Ok(()) => Ok(()),\n    Err(e) if e.to_string().contains(\"failed to find a template in\") => {\n        run_forc_template(url, project, Some(\"counter\")) // retry with an explicit template dir\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Default to passing --template-name for collection-style template repos","If you maintain a template repo, keep a root Forc.toml so bare `forc template <url>` works"],"tags":["forc","template","manifest","repo-root"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}