{"record":{"id":"65e8ee4625ae9c25","repo":"chenhg5/cc-connect","slug":"write-new-binary-w","errorCode":null,"errorMessage":"write new binary: %w","messagePattern":"write new binary: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/updater.go","lineNumber":265,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"get executable path: %w\", err)\n\t}\n\texecPath, err = filepath.EvalSymlinks(execPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"resolve symlinks: %w\", err)\n\t}\n\n\tdir := filepath.Dir(execPath)\n\ttmpFile, err := os.CreateTemp(dir, \"cc-connect-update-*\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create temp file: %w\", err)\n\t}\n\ttmpPath := tmpFile.Name()\n\n\tif _, err := tmpFile.Write(newBinary); err != nil {\n\t\ttmpFile.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"write new binary: %w\", err)\n\t}\n\ttmpFile.Close()\n\n\tif err := os.Chmod(tmpPath, 0o755); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"chmod: %w\", err)\n\t}\n\n\toldPath := execPath + \".old\"\n\tos.Remove(oldPath)\n\n\tif err := os.Rename(execPath, oldPath); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"backup old binary: %w\", err)\n\t}\n\n\tif err := os.Rename(tmpPath, execPath); err != nil {\n\t\t// Try to restore","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/updater.go#L247-L283","documentation":"After creating the temp file, replaceBinary writes the downloaded binary bytes; any short/failed write is cleaned up (close + remove) and wrapped as \"write new binary: %w\". This guarantees no half-written temp file is left behind.","triggerScenarios":"SelfUpdate -> replaceBinary: tmpFile.Write(newBinary) returned an error — disk filled while writing, file descriptor closed unexpectedly, I/O error on the underlying device, or quota exceeded on the volume holding the binary.","commonSituations":"Disk hit 100% between the temp-file creation and the write; NFS/EBS device error or disconnection; user quota on the home volume; very large new binary exceeding remaining space.","solutions":["Free disk space (df -h) and retry the update — this is nearly always ENOSPC.","Check dmesg / device logs for I/O errors if the disk is local; replace or repair the failing device.","Verify volume quotas (quota -s) and raise or clean up if the user quota is exhausted.","Retry after transient network-storage issues (NFS remount) since the updater removes the partial temp file automatically.","If it recurs on the same volume, move the binary installation to a more reliable local disk."],"exampleFix":"# before\n$ cc-connect update\n# write new binary: write /opt/cc-connect/cc-connect-update-123: no space left on device\n# after\n$ df -h && rm -rf /var/log/old-logs && cc-connect update","handlingStrategy":"validation","validationCode":"if err := syscall.Access(installDir, unix.W_OK); err != nil {\n    return err\n}\nvar st syscall.Statfs_t\nif err := syscall.Statfs(installDir, &st); err == nil {\n    if st.Bavail*uint64(st.Bsize) < uint64(len(newBinary)) {\n        return fmt.Errorf(\"insufficient disk space for update\")\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := selfUpdate(); err != nil {\n    if strings.Contains(err.Error(), \"write new binary\") {\n        // free disk space (ENOSPC) and retry\n    }\n}","preventionTips":["Monitor free space on the volume holding the binary","Avoid NFS/EBS mounts with flaky I/O for the install dir","Set volume quotas above the expected binary size"],"tags":["filesystem","disk","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"}