{"record":{"id":"5463117a6fa57b3c","repo":"chenhg5/cc-connect","slug":"install-new-binary-w","errorCode":null,"errorMessage":"install new binary: %w","messagePattern":"install new binary: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/update.go","lineNumber":447,"sourceCode":"\tif err := os.Chmod(src, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"chmod: %w\", err)\n\t}\n\n\t// On Windows, rename over a running exe is not possible directly.\n\t// Move old binary aside, then move new one in.\n\tbackup := target + \".old\"\n\tos.Remove(backup)\n\n\tif err := os.Rename(target, backup); err != nil {\n\t\treturn fmt.Errorf(\"backup old binary: %w\", err)\n\t}\n\n\tif err := copyFile(src, target); err != nil {\n\t\t// Attempt to restore\n\t\tif restoreErr := os.Rename(backup, target); restoreErr != nil {\n\t\t\tslog.Warn(\"update: failed to restore old binary after copy error\", \"error\", restoreErr)\n\t\t}\n\t\treturn fmt.Errorf(\"install new binary: %w\", err)\n\t}\n\n\tif err := os.Chmod(target, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"chmod new binary: %w\", err)\n\t}\n\n\tos.Remove(backup)\n\treturn nil\n}\n\nfunc copyFile(src, dst string) error {\n\tin, err := os.Open(src)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer in.Close()\n\n\tout, err := os.Create(dst)","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/update.go#L429-L465","documentation":"replaceExecutable copies the freshly built binary over the running install path during `cc-connect update`. When copyFile fails (e.g. disk full, target busy, permission issue), it tries to restore the backup of the old binary and wraps the copy error as \"install new binary: %w\". This means the update's install step failed, though the tool attempted to roll back to the previous binary.","triggerScenarios":"Running `cc-connect update`; replaceExecutable is called from runUpdate after a successful build, and os.CopyFile/copyFile(src, target) fails — typically write errors on the target path, out-of-disk, or the target being locked.","commonSituations":"Disk quota exceeded on the volume holding the binary; target directory owned by root while running as non-root; antivirus/file-lock on Windows-style mounts; read-only filesystem after a failed mount; interrupted download leaving a corrupt build in src.","solutions":["Check free disk space (df -h) on the filesystem containing the binary and free space if full.","Verify write permissions on the target path (ls -l $(which cc-connect)) and re-run with sufficient privileges.","Check the wrapped root cause in the error message (%w) and logs: 'update: failed to restore old binary after copy error' would indicate the rollback also failed.","As a fallback, manually download/build the new binary and replace it, then restart the daemon.","If the target is locked by a running process, stop the cc-connect daemon/service before updating."],"exampleFix":"// before (run as unprivileged user, target owned by root)\ncc-connect update\n// install new binary: chmod /usr/local/bin/cc-connect: permission denied\n\n// after\nsudo chown $(whoami) /usr/local/bin/cc-connect\ncc-connect update","handlingStrategy":"try-catch","validationCode":"if st, err := os.Stat(target); err == nil {\n    if f, err := os.OpenFile(target, os.O_WRONLY, st.Mode()); err != nil {\n        return fmt.Errorf(\"target not writable: %w\", err)\n    } else { f.Close() }\n}","typeGuard":null,"tryCatchPattern":"if err := runUpdate(); err != nil {\n    if strings.Contains(err.Error(), \"install new binary\") {\n        slog.Warn(\"update failed at install step; old binary may have been restored\", \"err\", err)\n        // verify binary still runs before retrying\n    }\n}","preventionTips":["Check disk space before running self-update","Run the update with the same user that owns the binary","Stop the daemon/service before updating on platforms that lock files","Keep a known-good copy of the previous binary"],"tags":["update","file-write-failed","self-update"],"backgroundTag":"file-write-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}