matryer/xbar · error

create temp file

Error message

create temp file

What it means

os.CreateTemp failed while creating a temporary file to hold the downloaded zip; the error is wrapped as 'create temp file'. CreateTemp uses the default temp directory (empty dir string) and a pattern of '*-'+filename.

Source

Thrown at pkg/update/update.go:196

}

func (u *Updater) downloadAndReplaceApp(asset Asset) error {
	filename := path.Base(asset.BrowserDownloadURL)
	switch {
	case strings.HasSuffix(filename, ".zip"):
		// fine
	default:
		return errors.Errorf("file not supported: %s", filename)
	}
	resp, err := u.Client.Get(asset.BrowserDownloadURL)
	if err != nil {
		return errors.Wrap(err, "download asset")
	}
	defer resp.Body.Close()
	const defaultTempDir = ""
	f, err := os.CreateTemp(defaultTempDir, "*-"+filename)
	if err != nil {
		return errors.Wrap(err, "create temp file")
	}
	_, err = io.Copy(f, io.LimitReader(resp.Body, u.DownloadBytesLimit))
	if err != nil {
		f.Close()
		return errors.Wrap(err, "download asset")
	}
	f.Close()
	executable, err := u.GetExecutable()
	if err != nil {
		return errors.Wrap(err, "get executable")
	}
	appPath, err := appPathFromExecutable(executable)
	if err != nil {
		return errors.Wrap(err, "find app path")
	}
	appPathDir := filepath.Dir(appPath)
	appPreviousPath := appPath + ".previous"
	err = os.Rename(appPath, appPreviousPath)

View on GitHub (pinned to d624239058)

Solutions

  1. Check disk space and that the OS temp dir (TMPDIR/TMP) exists and is writable.
  2. Sanitize the asset filename (strip path separators/illegal chars) before using it in the temp pattern.
  3. Point the process at a writable temp directory via TMPDIR.
  4. Fall back to os.CreateTemp("", "update-*") ignoring the remote filename.

Example fix

// before
f, err := os.CreateTemp(defaultTempDir, "*-"+filename)
// after
f, err := os.CreateTemp("", "app-update-*.zip")
Defensive patterns

Strategy: validation

Validate before calling

tmp := os.TempDir()
if fi, err := os.Stat(tmp); err != nil || !fi.IsDir() {
	return fmt.Errorf("temp dir %s unavailable: %v", tmp, err)
}
probe, err := os.CreateTemp(tmp, "probe-*")
if err != nil {
	return fmt.Errorf("temp dir not writable: %w", err)
}
probe.Close(); os.Remove(probe.Name())

Try / catch

err := u.Update()
if err != nil && strings.Contains(err.Error(), "create temp file") {
	os.Setenv("TMPDIR", "/var/tmp") // or a known-writable dir
	err = u.Update()
}

Prevention

When it happens

Trigger: Calling Update() when the temp directory is not writable, doesn't exist, has no space/inodes left, or the filename contains characters invalid for a temp file pattern on the OS.

Common situations: TMPDIR set to a non-existent or read-only path; read-only container filesystem or full disk; asset filename with path separators or illegal characters (e.g. ':' on Windows) breaking the temp pattern.

Related errors


AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02). Data as JSON: /api/errors/1102880be6159b72. Report an issue: GitHub.