{"record":{"id":"41a9e6b1f6fcd6fa","repo":"can1357/oh-my-pi","slug":"too-many-templates","errorCode":null,"errorMessage":"too many templates","messagePattern":"too many templates","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/mktemp.rs","lineNumber":72,"sourceCode":"\t#[error(\"could not persist file {}\", .0.quote())]\n\tPersist(PathBuf),\n\n\t#[error(\"with --suffix, template {} must end in X\", .0.quote())]\n\tMustEndInX(String),\n\n\t#[error(\"too few X's in template {}\", .0.quote())]\n\tTooFewXs(String),\n\n\t#[error(\"invalid template, {}, contains directory separator\", .0.quote())]\n\tPrefixContainsDirSeparator(String),\n\n\t#[error(\"invalid suffix {}, contains directory separator\", .0.quote())]\n\tSuffixContainsDirSeparator(String),\n\n\t#[error(\"invalid template, {}; with --tmpdir, it may not be absolute\", .0.quote())]\n\tInvalidTemplate(OsString),\n\n\t#[error(\"too many templates\")]\n\tTooManyTemplates,\n\n\t#[error(\"failed to create {} via template {}: No such file or directory\", .0, .1.quote())]\n\tNotFound(String, PathBuf),\n\n\t#[error(transparent)]\n\tIo(#[from] io::Error),\n}\n\n/// Options parsed from the command line.\n///\n/// This provides a layer of indirection between the application logic and\n/// `clap`, allowing each to vary independently.\n#[derive(Clone)]\nstruct Options {\n\t/// Whether to create a temporary directory instead of a file.\n\tdirectory: bool,\n\t/// Whether to just print the name of a file that would have been created.","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/mktemp.rs#L54-L90","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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\"`."],"exampleFix":"# before\nmktemp \"$TMPDIR/build.XXXXXX\" \"$TMPDIR/cache.XXXXXX\"\n# after\nmktemp -d \"$TMPDIR\" build.XXXXXX  # one template per call; repeat the call as needed","handlingStrategy":"validation","validationCode":"if [ \"$#\" -gt 1 ]; then echo \"usage: mktemp [option]... [TEMPLATE]\" >&2; exit 64; fi  # one template max","typeGuard":null,"tryCatchPattern":"if ! out=$(mktemp -p \"$dir\" \"$tpl\" 2>&1); then echo \"mktemp failed: $out\" >&2; exit 1; fi","preventionTips":["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."],"tags":["cli","argument-parsing","mktemp","usage-error"],"backgroundTag":"too-many-operands","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}