{"record":{"id":"ff762472a3fccfef","repo":"chenhg5/cc-connect","slug":"backup-old-binary-w","errorCode":null,"errorMessage":"backup old binary: %w","messagePattern":"backup old binary: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/update.go","lineNumber":439,"sourceCode":"\t}\n\ttmp.Close()\n\n\tfmt.Printf(\"Downloaded %.1f MB\\n\", float64(size)/1024/1024)\n\treturn tmp.Name(), nil\n}\n\nfunc replaceExecutable(target, src string) error {\n\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","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/update.go#L421-L457","documentation":"Wraps a failed os.Rename moving the current executable aside to <target>.old in replaceExecutable (the Windows-safe swap path). It fires when the running binary cannot be renamed — target missing, permission denied, or antivirus locking the file on Windows.","triggerScenarios":"Thrown at cmd/cc-connect/update.go:439 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["On Windows, exclude the cc-connect directory from antivirus locking","Ensure the install directory is writable by the updating user","Retry once the lock is released"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}