can1357/oh-my-pi · error
too many templates
Error message
too many templates
What it means
GNU-compatible usage error from the `mktemp` builtin (crates/pi-builtins/src/mktemp.rs:72). `mktemp` accepts at most one TEMPLATE positional argument; passing more than one is invalid. The builtin intercepts clap's generic 'unexpected argument' diagnostic in `rewrite_argv` and replaces it with GNU mktemp's concise `too many templates` message. It is also raised under `POSIXLY_CORRECT` when the template is not the last argument.
Source
Thrown at crates/pi-builtins/src/mktemp.rs:72
#[error("could not persist file {}", .0.quote())]
Persist(PathBuf),
#[error("with --suffix, template {} must end in X", .0.quote())]
MustEndInX(String),
#[error("too few X's in template {}", .0.quote())]
TooFewXs(String),
#[error("invalid template, {}, contains directory separator", .0.quote())]
PrefixContainsDirSeparator(String),
#[error("invalid suffix {}, contains directory separator", .0.quote())]
SuffixContainsDirSeparator(String),
#[error("invalid template, {}; with --tmpdir, it may not be absolute", .0.quote())]
InvalidTemplate(OsString),
#[error("too many templates")]
TooManyTemplates,
#[error("failed to create {} via template {}: No such file or directory", .0, .1.quote())]
NotFound(String, PathBuf),
#[error(transparent)]
Io(#[from] io::Error),
}
/// Options parsed from the command line.
///
/// This provides a layer of indirection between the application logic and
/// `clap`, allowing each to vary independently.
#[derive(Clone)]
struct Options {
/// Whether to create a temporary directory instead of a file.
directory: bool,
/// Whether to just print the name of a file that would have been created.View on GitHub (pinned to 9690622007)
Solutions
- Remove the extra template operand — mktemp takes at most one; combine the directory and name pattern into a single template like `dir/prefix.XXXXXXXX`.
- Pass the directory via `--tmpdir DIR` (or `-p DIR`) instead of embedding it as a second positional argument.
- If POSIXLY_CORRECT is set, reorder the command so the template is the last argument (e.g. `mktemp -d foo.XXXX`).
- Quote variables that may word-split into multiple operands: `mktemp "$template"`.
Example fix
# before mktemp "$TMPDIR/build.XXXXXX" "$TMPDIR/cache.XXXXXX" # after mktemp -d "$TMPDIR" build.XXXXXX # one template per call; repeat the call as needed
Defensive patterns
Strategy: validation
Validate before calling
if [ "$#" -gt 1 ]; then echo "usage: mktemp [option]... [TEMPLATE]" >&2; exit 64; fi # one template max
Try / catch
if ! out=$(mktemp -p "$dir" "$tpl" 2>&1); then echo "mktemp failed: $out" >&2; exit 1; fi
Prevention
- Always pass exactly one template operand to mktemp.
- Use --tmpdir/-p for the directory instead of extra positional arguments.
- Quote interpolated variables to prevent accidental word splitting into multiple operands.
- When POSIXLY_CORRECT is set, put the template last in the argument list.
When it happens
Trigger: Running `mktemp one.XXXX two.XXXX` (two template operands); under `POSIXLY_CORRECT`, running `mktemp foo.XXXX -d` where the template appears before options so the template fails `template_is_last` in `Mktemp::run`.
Common situations: Scripts that interpolate extra path arguments into a mktemp call (e.g. `mktemp "$dir/$prefix.XXXX" "$dir2/..."` after a variable expansion yields multiple words); porting scripts between shells where a flag was consumed differently; enabling POSIXLY_CORRECT in an environment with option-after-template invocations.
Related errors
- --trusted-extension requires a non-empty, non-flag value
- Usage: omp auth-broker login <provider> --via=user@host (pro
- with --suffix, template {} must end in X
- too few X's in template {}
- invalid template, {}, contains directory separator
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/41a9e6b1f6fcd6fa.
Report an issue: GitHub.