{"record":{"id":"b25e276ebc23af04","repo":"chenhg5/cc-connect","slug":"write-formatted-config-w","errorCode":null,"errorMessage":"write formatted config: %w","messagePattern":"write formatted config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":3723,"sourceCode":"\t}\n\tcfg := &Config{}\n\tif err := toml.Unmarshal(data, cfg); err != nil {\n\t\treturn fmt.Errorf(\"invalid TOML: %w\", err)\n\t}\n\tformatted := formatTOML(string(data))\n\tif formatted == string(data) {\n\t\treturn nil\n\t}\n\tdir := filepath.Dir(path)\n\ttmp, err := os.CreateTemp(dir, \".config-*.tmp\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create temp file: %w\", err)\n\t}\n\ttmpPath := tmp.Name()\n\tif _, err := tmp.WriteString(formatted); err != nil {\n\t\ttmp.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"write formatted config: %w\", err)\n\t}\n\tif err := tmp.Sync(); err != nil {\n\t\ttmp.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn err\n\t}\n\tif err := tmp.Close(); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn err\n\t}\n\treturn os.Rename(tmpPath, path)\n}\n\n// GetGlobalSettings reads global settings from config.toml.\nfunc GetGlobalSettings() map[string]any {\n\tif ConfigPath == \"\" {\n\t\treturn nil\n\t}","sourceCodeStart":3705,"sourceCodeEnd":3741,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/config/config.go#L3705-L3741","documentation":"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.","triggerScenarios":"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.","commonSituations":"Disk/quota exhaustion during the write; flaky network filesystem; security policy (SELinux/AppArmor) denying writes to the newly created temp file.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure headroom before formatting\nif avail, err := freeBytes(filepath.Dir(path)); err == nil && avail < 1<<20 {\n    return fmt.Errorf(\"insufficient disk space to format %s\", path)\n}","typeGuard":null,"tryCatchPattern":"if err := config.FormatConfigFile(path); err != nil {\n    if strings.Contains(err.Error(), \"write formatted config:\") {\n        time.Sleep(500 * time.Millisecond)\n        return config.FormatConfigFile(path) // original file untouched; safe retry\n    }\n    return err\n}","preventionTips":["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."],"tags":["config","file-io","write","disk"],"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"}