chenhg5/cc-connect · error
write formatted config: %w
Error message
write formatted config: %w
What it means
Inside FormatConfigFile, tmp.WriteString(formatted) persisting the reformatted TOML can fail; the handler closes and removes the temp file and returns this wrapped error. As with all write paths here, the original config is untouched because the atomic rename happens only after a successful Sync.
Source
Thrown at config/config.go:3723
}
cfg := &Config{}
if err := toml.Unmarshal(data, cfg); err != nil {
return fmt.Errorf("invalid TOML: %w", err)
}
formatted := formatTOML(string(data))
if formatted == string(data) {
return nil
}
dir := filepath.Dir(path)
tmp, err := os.CreateTemp(dir, ".config-*.tmp")
if err != nil {
return fmt.Errorf("create temp file: %w", err)
}
tmpPath := tmp.Name()
if _, err := tmp.WriteString(formatted); err != nil {
tmp.Close()
os.Remove(tmpPath)
return fmt.Errorf("write formatted 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, path)
}
// GetGlobalSettings reads global settings from config.toml.
func GetGlobalSettings() map[string]any {
if ConfigPath == "" {
return nil
}View on GitHub (pinned to 4000b2338a)
Solutions
- Free disk space and re-run the format command.
- Investigate filesystem errors in system logs if the failure repeats.
- Retry — the temp file is removed on failure and the original config remains valid.
Defensive patterns
Strategy: retry
Validate before calling
// Ensure headroom before formatting
if avail, err := freeBytes(filepath.Dir(path)); err == nil && avail < 1<<20 {
return fmt.Errorf("insufficient disk space to format %s", path)
} Try / catch
if err := config.FormatConfigFile(path); err != nil {
if strings.Contains(err.Error(), "write formatted config:") {
time.Sleep(500 * time.Millisecond)
return config.FormatConfigFile(path) // original file untouched; safe retry
}
return err
} Prevention
- Monitor disk space; mid-write ENOSPC is the dominant cause.
- Avoid network filesystems for config storage.
- Trust the atomic-write design: on this error the original file remains valid, so retry freely.
When it happens
Trigger: tmp.WriteString(formatted) errors in FormatConfigFile (config/config.go:3723): disk full mid-write, filesystem I/O error, or the fd became invalid after CreateTemp.
Common situations: Disk/quota exhaustion during the write; flaky network filesystem; security policy (SELinux/AppArmor) denying writes to the newly created temp file.
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/b25e276ebc23af04.
Report an issue: GitHub.