plandex-ai/plandex · error

failed to apply update: %w

Error message

failed to apply update: %w

What it means

If update.Apply fails for any reason other than fs.ErrPermission, doUpgrade returns the generic 'failed to apply update: %w'. go-update writes the new binary to a temp file, optionally verifies checksums, and renames it over the old executable; failures here include non-permission filesystem errors and (since Options{} sets no target path) errors replacing the currently running binary.

Source

Thrown at app/cli/upgrade.go:152

	tarReader := tar.NewReader(gzr)
	for {
		header, err := tarReader.Next()
		if err == io.EOF {
			break // End of archive
		}
		if err != nil {
			return fmt.Errorf("failed to read tar header: %w", err)
		}

		// Check if the current file is the binary
		if header.Typeflag == tar.TypeReg && (header.Name == "plandex" || header.Name == "plandex.exe") {
			err = update.Apply(tarReader, update.Options{})
			if err != nil {
				if errors.Is(err, fs.ErrPermission) {
					return fmt.Errorf("failed to apply update due to permission error; please try running your command again with 'sudo': %w", err)
				}
				return fmt.Errorf("failed to apply update: %w", err)
			}
			break
		}
	}

	return nil
}

func restartPlandex() {
	exe, err := os.Executable()
	if err != nil {
		term.OutputErrorAndExit("Failed to determine executable path: %v", err)
	}

	cmd := exec.Command(exe, os.Args[1:]...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

View on GitHub (pinned to e2d772072e)

Solutions

  1. Free disk space before retrying the upgrade.
  2. Install manually: download the release tar.gz, extract, and replace the binary yourself.
  3. If the binary is in an OS-managed read-only path (e.g. Nix store, immutable OS), reinstall through that system's package manager instead of self-update.
  4. Check for antivirus/file-lock interference (Windows) and retry.

Example fix

// before (self-update against a read-only system path)
/usr/local/bin/plandex  # immutable location -> update.Apply fails
// after (install to writable location first)
$ mkdir -p ~/.local/bin
$ tar -xzf plandex_*_$(uname -s | tr A-Z a-z)_$(uname -m).tar.gz
$ mv plandex ~/.local/bin/ && export PATH=$HOME/.local/bin:$PATH
Defensive patterns

Strategy: try-catch

Validate before calling

exe, _ := os.Executable()
realPath, _ := filepath.EvalSymlinks(exe)
if err := unix.Access(filepath.Dir(realPath), unix.W_OK); err != nil {
	return fmt.Errorf("cannot self-update: install dir %s is read-only", filepath.Dir(realPath))
}

Try / catch

err = update.Apply(tarReader, update.Options{})
if err != nil {
	if errors.Is(err, fs.ErrPermission) {
		// handle permission case separately (sudo hint)
	} else {
		fmt.Printf("Self-update failed (%v); falling back to manual install instructions\n", err)
	}
}

Prevention

When it happens

Trigger: update.Apply fails with a non-permission error: disk full while staging the new binary, cross-device rename problems, the running executable path is a symlink into a read-only location, or an unexpected go-update internal error.

Common situations: Read-only root filesystem (immutable containers, NixOS-style stores); binary on a different device than temp staging; antivirus locking the executable on Windows; full disk.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/f0931b72c431f816. Report an issue: GitHub.