can1357/oh-my-pi · error
failed to create {} via template {}: No such file or directo
Error message
failed to create {} via template {}: No such file or directory What it means
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.
Source
Thrown at crates/pi-builtins/src/mktemp.rs:75
#[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.
dry_run: bool,
/// Whether to suppress file creation error messages.
quiet: bool,View on GitHub (pinned to 9690622007)
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).
Example fix
# before mktemp -p "$WORK/cache" tmp.XXXXXX # fails if cache/ missing # after mkdir -p "$WORK/cache" mktemp -p "$WORK/cache" tmp.XXXXXX
Defensive patterns
Strategy: validation
Validate before calling
mkdir -p "${TMPDIR:-/tmp}"
[ -d "${TMPDIR:-/tmp}" ] || { echo "tmpdir missing" >&2; exit 1; } Try / catch
if ! out=$(mktemp -p "$dir" foo.XXXX); then echo "mktemp: cannot create in $dir" >&2; exit 1; fi
Prevention
- 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.
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- could not persist file {}
- Too many levels of symbolic links
- {}: {error}
- failed to create a unique fc temporary file
- 2
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/1b8f6bb8493f6849.
Report an issue: GitHub.