nikivdev/code · error
Template not found: {}
Error message
Template not found: {} What it means
Thrown by new_from_template (src/code.rs:104) when the explicitly supplied template name does not correspond to an existing entry under ~/new/. The error prints the fully joined path so the exact location checked is visible.
Source
Thrown at src/code.rs:104
/// Create a new project from a template at a specific path.
/// Usage: f new [template] [path]
pub fn new_from_template(opts: NewOpts) -> Result<()> {
let template_root = config::expand_path(DEFAULT_TEMPLATE_ROOT);
// Get template name (fuzzy select if not provided)
let template_name = match opts.template {
Some(t) => t,
None => match fuzzy_select_template()? {
Some(t) => t,
None => return Ok(()), // User cancelled
},
};
let template_dir = template_root.join(template_name.trim());
if !template_dir.exists() {
bail!("Template not found: {}", template_dir.display());
}
if !template_dir.is_dir() {
bail!(
"Template path is not a directory: {}",
template_dir.display()
);
}
// Resolve target path:
// - No path: ./<template_name>
// - Starts with ./ or ../: relative to cwd
// - Starts with ~ or /: absolute path
// - Otherwise: relative to ~/code/
let target = match opts.path {
None => std::env::current_dir()?.join(&template_name),
Some(p) => {
let trimmed = p.trim();
if trimmed.starts_with("./")View on GitHub (pinned to a747e741ae)
Solutions
- Run `ls ~/new` and use the exact template directory name shown.
- Create the missing template directory: `mkdir -p ~/new/<name>`.
- Omit the template argument (`f new`) to pick interactively from existing templates.
- Check for case/whitespace differences in the name you passed.
Example fix
// before $ f new rust_clib ~/code/proj Error: Template not found: /home/user/new/rust_clib // after $ ls ~/new # shows rust-cli $ f new rust-cli ~/code/proj
Defensive patterns
Strategy: validation
Validate before calling
// Shell: confirm the template exists before invoking
TPL="$HOME/new/$TEMPLATE_NAME"
[ -d "$TPL" ] || { echo "template missing: $TPL; available:"; ls "$HOME/new"; exit 1; } Type guard
fn template_exists(name: &str) -> bool {
config::expand_path("~/new").join(name.trim()).is_dir()
} Try / catch
match new_from_template(opts) {
Err(e) if e.to_string().contains("Template not found") => {
eprintln!("Unknown template; run `ls ~/new` for available templates.");
}
other => other?,
} Prevention
- Keep a canonical list of template names and validate against it in scripts
- Use tab-completion or `ls ~/new` rather than typing template names from memory
- Note Linux path names are case-sensitive; prefer lowercase template dirs
When it happens
Trigger: Running `f new <template> <path>` where expand_path(~/new).join(template) does not exist — wrong name, wrong case, template deleted, or trailing whitespace already handled via trim().
Common situations: Typo in the template name; template directory renamed after docs/scripts referenced it; running on a machine that never received the template; case-sensitivity on Linux (MyTemplate vs mytemplate).
Related errors
- Source folder does not exist: {}
- Diff bundle not found. Expected {} or pass a path to a bundl
- Template path is not a directory: {}
- Usage: f migrate <target> OR f migrate <source> <target> OR
- Could not find agent file for '{}'
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/8aecbe75285cff6f.
Report an issue: GitHub.