{"record":{"id":"f0931b72c431f816","repo":"plandex-ai/plandex","slug":"failed-to-apply-update-w","errorCode":null,"errorMessage":"failed to apply update: %w","messagePattern":"failed to apply update: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/upgrade.go","lineNumber":152,"sourceCode":"\n\ttarReader := tar.NewReader(gzr)\n\tfor {\n\t\theader, err := tarReader.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak // End of archive\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to read tar header: %w\", err)\n\t\t}\n\n\t\t// Check if the current file is the binary\n\t\tif header.Typeflag == tar.TypeReg && (header.Name == \"plandex\" || header.Name == \"plandex.exe\") {\n\t\t\terr = update.Apply(tarReader, update.Options{})\n\t\t\tif err != nil {\n\t\t\t\tif errors.Is(err, fs.ErrPermission) {\n\t\t\t\t\treturn fmt.Errorf(\"failed to apply update due to permission error; please try running your command again with 'sudo': %w\", err)\n\t\t\t\t}\n\t\t\t\treturn fmt.Errorf(\"failed to apply update: %w\", err)\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc restartPlandex() {\n\texe, err := os.Executable()\n\tif err != nil {\n\t\tterm.OutputErrorAndExit(\"Failed to determine executable path: %v\", err)\n\t}\n\n\tcmd := exec.Command(exe, os.Args[1:]...)\n\tcmd.Stdin = os.Stdin\n\tcmd.Stdout = os.Stdout\n\tcmd.Stderr = os.Stderr","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/upgrade.go#L134-L170","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Free disk space before retrying the upgrade.","Install manually: download the release tar.gz, extract, and replace the binary yourself.","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.","Check for antivirus/file-lock interference (Windows) and retry."],"exampleFix":"// before (self-update against a read-only system path)\n/usr/local/bin/plandex  # immutable location -> update.Apply fails\n// after (install to writable location first)\n$ mkdir -p ~/.local/bin\n$ tar -xzf plandex_*_$(uname -s | tr A-Z a-z)_$(uname -m).tar.gz\n$ mv plandex ~/.local/bin/ && export PATH=$HOME/.local/bin:$PATH","handlingStrategy":"try-catch","validationCode":"exe, _ := os.Executable()\nrealPath, _ := filepath.EvalSymlinks(exe)\nif err := unix.Access(filepath.Dir(realPath), unix.W_OK); err != nil {\n\treturn fmt.Errorf(\"cannot self-update: install dir %s is read-only\", filepath.Dir(realPath))\n}","typeGuard":null,"tryCatchPattern":"err = update.Apply(tarReader, update.Options{})\nif err != nil {\n\tif errors.Is(err, fs.ErrPermission) {\n\t\t// handle permission case separately (sudo hint)\n\t} else {\n\t\tfmt.Printf(\"Self-update failed (%v); falling back to manual install instructions\\n\", err)\n\t}\n}","preventionTips":["Ensure the install location is on a writable filesystem","Keep enough free disk space for staging the new binary","Don't self-update binaries managed by a package manager/immutable OS","Handle non-permission Apply failures with a manual-install fallback"],"tags":["upgrade","filesystem","go-update","self-update"],"backgroundTag":"self-update-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}