{"record":{"id":"1b8f6bb8493f6849","repo":"can1357/oh-my-pi","slug":"failed-to-create-via-template-no-such-file","errorCode":null,"errorMessage":"failed to create {} via template {}: No such file or directory","messagePattern":"failed to create (.+?) via template (.+?): No such file or directory","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/mktemp.rs","lineNumber":75,"sourceCode":"\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.\n\tdry_run: bool,\n\t/// Whether to suppress file creation error messages.\n\tquiet: bool,","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/mktemp.rs#L57-L93","documentation":"Creation failure from the `mktemp` builtin (crates/pi-builtins/src/mktemp.rs:75). When `tempfile_in`/`tempdir_in` returns `ErrorKind::NotFound`, the builtin converts it into this explicit message naming the resolved target path and the quoted template. It means the parent directory of the constructed temporary path does not exist.","triggerScenarios":"`mktemp -p missing-dir foo.XXXX` (or `--tmpdir`) where DIR does not exist; a template with a directory component like `sub/foo.XXXX` when `sub/` is absent; `TMPDIR` pointing to a non-existent directory while using `--tmpdir` (no argument), `-t`, or no template.","commonSituations":"Scripts using `$TMPDIR` set to a stale or never-created directory; a `--tmpdir` value with a typo or created later by another step of the script; templates like `cache/out.XXXX` where the `cache` directory was cleaned up beforehand.","solutions":["Create the target directory before invoking mktemp: `mkdir -p \"$TMPDIR\"` or `mkdir -p missing-dir`.","Check the value of `TMPDIR`/`TMP` for typos or stale paths and correct or unset it.","Simplify the template to a single filename component and pass the directory via `-p`/`--tmpdir` so the missing piece is obvious.","Use `-q` if the script only needs the exit code without the diagnostic (the exit code stays 1)."],"exampleFix":"# before\nmktemp -p \"$WORK/cache\" tmp.XXXXXX   # fails if cache/ missing\n# after\nmkdir -p \"$WORK/cache\"\nmktemp -p \"$WORK/cache\" tmp.XXXXXX","handlingStrategy":"validation","validationCode":"mkdir -p \"${TMPDIR:-/tmp}\"\n[ -d \"${TMPDIR:-/tmp}\" ] || { echo \"tmpdir missing\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"if ! out=$(mktemp -p \"$dir\" foo.XXXX); then echo \"mktemp: cannot create in $dir\" >&2; exit 1; fi","preventionTips":["mkdir -p the tmpdir (and any directory components embedded in the template) before calling mktemp.","Validate TMPDIR/TMP points at an existing directory at script start.","Prefer a single filename-component template plus -p DIR over slashes inside the template.","Check mktemp's exit status rather than blindly using its output path."],"tags":["filesystem","mktemp","missing-directory","io"],"backgroundTag":"no-such-file-or-directory","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}