multica-ai/multica · error

write temp file: %w

Error message

write temp file: %w

What it means

Writing the extracted binary into the just-created temp file failed, wrapped as 'write temp file: %w'; the temp file is closed and removed before returning. The binary (~tens of MB) must fully land on disk before the rename, so ENOSPC (disk full), EDQUOT (quota), or an I/O error on a failing device surfaces here.

Source

Thrown at server/internal/cli/update.go:456

	} else {
		binaryData, err = extractBinaryFromTarGz(bytes.NewReader(archiveData), binaryName)
	}
	if err != nil {
		return "", fmt.Errorf("extract binary: %w", err)
	}

	// Atomic replace: write to temp file, then rename over the original.
	dir := filepath.Dir(exePath)
	tmpFile, err := os.CreateTemp(dir, "multica-update-*")
	if err != nil {
		return "", fmt.Errorf("create temp file: %w", err)
	}
	tmpPath := tmpFile.Name()

	if _, err := tmpFile.Write(binaryData); err != nil {
		tmpFile.Close()
		os.Remove(tmpPath)
		return "", fmt.Errorf("write temp file: %w", err)
	}
	tmpFile.Close()

	// Preserve original file permissions.
	info, err := os.Stat(exePath)
	if err != nil {
		os.Remove(tmpPath)
		return "", fmt.Errorf("stat original binary: %w", err)
	}
	if err := os.Chmod(tmpPath, info.Mode()); err != nil {
		os.Remove(tmpPath)
		return "", fmt.Errorf("chmod temp file: %w", err)
	}

	// Replace the original binary. On Windows this moves the running executable
	// aside first; on Unix a plain rename over the running inode is fine.
	if err := replaceBinary(tmpPath, exePath); err != nil {
		os.Remove(tmpPath)

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Free space on the filesystem holding the binary directory and retry (df <dir>).
  2. Raise the user's quota if EDQUOT.
  3. Exclude the binary directory from aggressive AV scanning on Windows.
  4. On storage I/O errors, remount/replace the failing disk — repeated write failures are hardware symptoms.

Example fix

null
Defensive patterns

Strategy: retry

Validate before calling

var stat syscall.Statfs_t
if err := syscall.Statfs(filepath.Dir(exePath), &stat); err == nil {
    free := stat.Bavail * uint64(stat.Bsize)
    if free < uint64(len(binaryData))+1<<20 { // payload + 1MB headroom
        // not enough space: clean up before updating
    }
}

Try / catch

out, err := cli.UpdateViaDownload(ver)
if err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOSPC) {
        // free space and retry; the temp file was already cleaned up by the updater
    }
}

Prevention

When it happens

Trigger: Disk filled between CreateTemp and Write; per-user quota exceeded; the filesystem degraded (NFS/overlayfs write errors, SD-card failure); antivirus/EDR on Windows locking the temp file mid-write.

Common situations: Small VM disks; overlay2 containers with a full upper layer; the update firing right as a log file fills the last space.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/15162dc9f9b9a2ab. Report an issue: GitHub.