chenhg5/cc-connect · error
write config: %w
Error message
write config: %w
What it means
saveConfig writes the formatted TOML to the temp file with tmp.WriteString; a write failure is cleaned up (temp file closed and removed) and wrapped as "write config: %w". This is the in-place write step of the atomic config save.
Source
Thrown at config/config.go:1564
dir := filepath.Dir(ConfigPath)
tmp, err := os.CreateTemp(dir, ".config-*.tmp")
if err != nil {
return fmt.Errorf("create temp config: %w", err)
}
tmpPath := tmp.Name()
var buf strings.Builder
if err := toml.NewEncoder(&buf).Encode(cfg); err != nil {
tmp.Close()
os.Remove(tmpPath)
return fmt.Errorf("encode config: %w", err)
}
formatted := formatTOML(buf.String())
if _, err := tmp.WriteString(formatted); err != nil {
tmp.Close()
os.Remove(tmpPath)
return fmt.Errorf("write config: %w", err)
}
if err := tmp.Sync(); err != nil {
tmp.Close()
os.Remove(tmpPath)
return err
}
if err := tmp.Close(); err != nil {
os.Remove(tmpPath)
return err
}
return os.Rename(tmpPath, ConfigPath)
}
// formatTOML post-processes raw TOML encoder output to improve readability:
// - inserts blank lines before section/array-table headers
// - removes empty section headers (no key-value pairs between this header and the next)
//
// It deliberately keeps all key-value lines intact, including zero-value onesView on GitHub (pinned to 4000b2338a)
Solutions
- Free disk space / raise the quota on the volume holding the config directory and retry the operation.
- Check the wrapped cause for I/O errors and verify the filesystem health (dmesg, mount options).
- Move the config to a reliable local filesystem rather than a network mount.
Example fix
// before
// no space check before saving
cfg.Providers = append(cfg.Providers, p)
saveConfig(cfg)
// after
if err := checkDiskSpace(filepath.Dir(config.ConfigPath)); err != nil {
return err
}
cfg.Providers = append(cfg.Providers, p)
saveConfig(cfg) Defensive patterns
Strategy: retry
Validate before calling
if err := checkFreeSpace(filepath.Dir(config.ConfigPath), 1<<20); err != nil {
return err
} Try / catch
err := saveConfigOp()
if err != nil && strings.Contains(err.Error(), "write config") {
time.Sleep(500 * time.Millisecond)
err = saveConfigOp() // transient I/O: one retry
} Prevention
- Monitor disk usage and set alerts before volumes fill.
- Keep the config on local storage, not network filesystems.
- The library already cleans up temp files; do not accumulate .config-*.tmp leftovers in scripts.
When it happens
Trigger: The WriteString to the already-created temp file fails: filesystem became read-only, disk full/quota hit, I/O error, or the file descriptor entered an error state between creation and write.
Common situations: Disk filling up between temp-file creation and write; NFS/network filesystem failures; container storage limits hit mid-save.
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/033c884a4b4ae987.
Report an issue: GitHub.