chenhg5/cc-connect · error

write new binary: %w

Error message

write new binary: %w

What it means

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.

Source

Thrown at core/updater.go:265

	if err != nil {
		return fmt.Errorf("get executable path: %w", err)
	}
	execPath, err = filepath.EvalSymlinks(execPath)
	if err != nil {
		return fmt.Errorf("resolve symlinks: %w", err)
	}

	dir := filepath.Dir(execPath)
	tmpFile, err := os.CreateTemp(dir, "cc-connect-update-*")
	if err != nil {
		return fmt.Errorf("create temp file: %w", err)
	}
	tmpPath := tmpFile.Name()

	if _, err := tmpFile.Write(newBinary); err != nil {
		tmpFile.Close()
		os.Remove(tmpPath)
		return fmt.Errorf("write new binary: %w", err)
	}
	tmpFile.Close()

	if err := os.Chmod(tmpPath, 0o755); err != nil {
		os.Remove(tmpPath)
		return fmt.Errorf("chmod: %w", err)
	}

	oldPath := execPath + ".old"
	os.Remove(oldPath)

	if err := os.Rename(execPath, oldPath); err != nil {
		os.Remove(tmpPath)
		return fmt.Errorf("backup old binary: %w", err)
	}

	if err := os.Rename(tmpPath, execPath); err != nil {
		// Try to restore

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Free disk space (df -h) and retry the update — this is nearly always ENOSPC.
  2. Check dmesg / device logs for I/O errors if the disk is local; replace or repair the failing device.
  3. Verify volume quotas (quota -s) and raise or clean up if the user quota is exhausted.
  4. Retry after transient network-storage issues (NFS remount) since the updater removes the partial temp file automatically.
  5. If it recurs on the same volume, move the binary installation to a more reliable local disk.

Example fix

# before
$ cc-connect update
# write new binary: write /opt/cc-connect/cc-connect-update-123: no space left on device
# after
$ df -h && rm -rf /var/log/old-logs && cc-connect update
Defensive patterns

Strategy: validation

Validate before calling

if err := syscall.Access(installDir, unix.W_OK); err != nil {
    return err
}
var st syscall.Statfs_t
if err := syscall.Statfs(installDir, &st); err == nil {
    if st.Bavail*uint64(st.Bsize) < uint64(len(newBinary)) {
        return fmt.Errorf("insufficient disk space for update")
    }
}

Try / catch

if err := selfUpdate(); err != nil {
    if strings.Contains(err.Error(), "write new binary") {
        // free disk space (ENOSPC) and retry
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/65e8ee4625ae9c25. Report an issue: GitHub.