FuelLabs/sway · error · anyhow::Error
failed to find a template `{}` in {}
Error message
failed to find a template `{}` in {} What it means
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>".
Source
Thrown at forc/src/ops/forc_template.rs:50
let fetch_id = source::fetch_id(current_dir, fetch_ts);
println_action_green("Resolving", &format!("the HEAD of {}", source.repo));
let git_source = source::git::pin(fetch_id, &local_repo_name, source)?;
let repo_path = source::git::commit_path(
&local_repo_name,
&git_source.source.repo,
&git_source.commit_hash,
);
if !repo_path.exists() {
println_action_green("Fetching", git_source.to_string().as_str());
source::git::fetch(fetch_id, &local_repo_name, &git_source)?;
}
let from_path = match command.template_name {
Some(ref template_name) => manifest::find_dir_within(&repo_path, template_name)
.ok_or_else(|| {
anyhow!(
"failed to find a template `{}` in {}",
template_name,
command.url
)
})?,
None => {
let manifest_path = repo_path.join(constants::MANIFEST_FILE_NAME);
if PackageManifest::from_file(manifest_path).is_err() {
anyhow::bail!("failed to find a template in {}", command.url);
}
repo_path
}
};
// Create the target dir
let target_dir = current_dir.join(&command.project_name);
println_action_green(View on GitHub (pinned to 47e5e902fa)
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
Example fix
# before forc template https://github.com/example/templates myapp --template-name counterr # after forc template https://github.com/example/templates myapp --template-name counter
Defensive patterns
Strategy: validation
Validate before calling
// Before running forc template, verify the template dir exists in a local clone.
let template_dir = format!("{clone_dir}/{template_name}");
if !std::path::Path::new(&template_dir).is_dir() {
anyhow::bail!("template '{template_name}' not found under {clone_dir}; check exact name/case");
} Type guard
fn valid_template_name(name: &str) -> bool {
!name.is_empty() && !name.contains('/') && !name.contains("..")
} Try / catch
match run_forc_template(url, project, Some(&name)) {
Ok(()) => Ok(()),
Err(e) if e.to_string().contains("failed to find a template") => {
anyhow::bail!("list available templates in {url} and retry with the exact directory name")
}
Err(e) => Err(e),
} Prevention
- 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
When it happens
Trigger: `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).
Common situations: 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.
Related errors
- missing path for new command
- failed to find a template in {}
- failed to read {}: {}
- invalid 'source' entry for package {} lock: {:?}
- failed to parse dependency "{}": {}
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/3c0f56de6012e90e.
Report an issue: GitHub.