{"record":{"id":"46b45ca94f6b3384","repo":"multica-ai/multica","slug":"write-temp-config-file-w","errorCode":null,"errorMessage":"write temp config file: %w","messagePattern":"write temp config file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/internal/cli/config.go","lineNumber":362,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"task-local CLI config directory %q escapes root %q\", dir, root)\n\t\t\t}\n\t\t}\n\t}\n\tdata, err := json.MarshalIndent(cfg, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"encode CLI config: %w\", err)\n\t}\n\n\t// Write to a temp file in the same directory, then rename for atomicity.\n\ttmp, err := os.CreateTemp(dir, \".config-*.json.tmp\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create temp config file: %w\", err)\n\t}\n\ttmpPath := tmp.Name()\n\tif _, err := tmp.Write(append(data, '\\n')); err != nil {\n\t\ttmp.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"write temp config file: %w\", err)\n\t}\n\tif err := tmp.Close(); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"close temp config file: %w\", err)\n\t}\n\tif err := os.Chmod(tmpPath, 0o600); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"chmod temp config file: %w\", err)\n\t}\n\tif err := os.Rename(tmpPath, path); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"rename config file: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":344,"sourceCodeEnd":378,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/internal/cli/config.go#L344-L378","documentation":"After creating the temp file, the write of the marshaled JSON failed. The temp file is closed and removed, so no partial file lingers. Typical causes are ENOSPC (disk filled during the write) or EIO on failing storage.","triggerScenarios":"SaveCLIConfig with the disk filling up between file creation and the (small) write, or a hardware/NFS write error surfacing at write() time.","commonSituations":"Home partition at 100% capacity; a flaky network mount dropping mid-write; disk quota exceeded for the user.","solutions":["Free disk space or raise the user quota on the affected filesystem","If on NFS/network storage, remount or reconnect and retry the save","Check dmesg/I/O errors for failing hardware","Retry the command once space is available — the atomic rename means the old config (if any) is still intact"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := cli.SaveCLIConfig(cfg)\nfor attempt := 0; errors.Is(err, syscall.ENOSPC) && attempt < 2; attempt++ {\n\ttime.Sleep(time.Second)\n\terr = cli.SaveCLIConfig(cfg)\n}","preventionTips":["Treat ENOSPC/EIO on config writes as transient storage conditions: alert and retry","Keep the config small and on reliable storage","The temp-file cleanup means no partial file is left behind"],"tags":["filesystem","disk-space","io","go"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}