can1357/oh-my-pi · critical · MkTempError

could not persist file {}

Error message

could not persist file {}

What it means

MkTempError::Persist is raised by the builtin `mktemp` when the temporary file it created could not be persisted — i.e. the final write/rename/fsync of the created file under the target directory failed. The error carries the offending PathBuf so you can see which path failed. This typically indicates a filesystem-level problem rather than a template problem (template issues have their own variants).

Source

Thrown at crates/pi-builtins/src/mktemp.rs:54

static OPT_DRY_RUN: &str = "dry-run";
static OPT_QUIET: &str = "quiet";
static OPT_SUFFIX: &str = "suffix";
static OPT_TMPDIR: &str = "tmpdir";
static OPT_P: &str = "p";
static OPT_T: &str = "t";

static ARG_TEMPLATE: &str = "template";

#[cfg(not(windows))]
const TMPDIR_ENV_VAR: &str = "TMPDIR";
#[cfg(windows)]
const TMPDIR_ENV_VAR: &str = "TMP";

const FALLBACK_TMPDIR: &str = "/tmp";

#[derive(Error, Debug)]
enum MkTempError {
	#[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")]

View on GitHub (pinned to 9690622007)

Solutions

  1. Check disk space (`df -h /tmp`) and free space or raise the quota
  2. Verify TMP / --tmpdir points to a writable, non-read-only directory
  3. Retry the operation — transient EIO/ENOSPC on the target filesystem may clear
  4. Choose a different tmpdir on a healthier filesystem via --tmpdir
  5. Check filesystem logs / dmesg for I/O errors on the underlying device

Example fix

// before
TMP=/mnt/failing-nfs mktemp
// after
TMP=/tmp mktemp   // or pass --tmpdir=/var/tmp
Defensive patterns

Strategy: try-catch

Validate before calling

const tmpDir = process.env.TMP ?? '/tmp';
await fs.access(tmpDir, fs.constants.W_OK);
const stat = await fs.statfs(tmpDir);
if (stat.bavail * stat.bsize < 1_000_000) throw new Error('low disk space in tmpdir');

Type guard

const isWritableDir = async (p: string): Promise<boolean> => {
  try { await fs.access(p, fs.constants.W_OK); return (await fs.stat(p)).isDirectory(); }
  catch { return false; }
};

Try / catch

try {
  await Bun.$`mktemp ${tmpl}`.quiet();
} catch (e) {
  if (String(e).includes('could not persist file')) {
    // fall back to an alternate tmpdir
    await Bun.$`mktemp --tmpdir=/var/tmp ${tmpl}`.quiet();
  } else throw e;
}

Prevention

When it happens

Trigger: Creating a temp file in a directory that becomes read-only or full between creation and persistence; tmpdir on a filesystem that rejects the write; TMP env var pointing to a failing mount; disk-quota exhaustion mid-operation.

Common situations: /tmp filled to capacity on small root partitions; read-only remounts after errors; sandboxed CI runners with restricted write access to TMP; NFS mounts dropping writes.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/0ce74b73c21aa35d. Report an issue: GitHub.