{"record":{"id":"0f817d3e3729758f","repo":"multica-ai/multica","slug":"rename-config-file-w","errorCode":null,"errorMessage":"rename config file: %w","messagePattern":"rename config file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/internal/cli/config.go","lineNumber":374,"sourceCode":"\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":356,"sourceCodeEnd":378,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/internal/cli/config.go#L356-L378","documentation":"The final atomic step — os.Rename of the temp file over config.json — failed. Common errnos: EXDEV cannot happen (same directory), so in practice this is EACCES/EPERM from directory permissions or a stale handle on Windows systems where the destination is open in another process.","triggerScenarios":"SaveCLIConfig when the config directory is not writable by the current user at rename time, or (on Windows) when another process holds config.json open, or when the destination is a directory.","commonSituations":"Ownership changed by an earlier sudo run; an editor or the daemon holding the config file open on Windows; MULTICA_TASK_CONFIG_ROOT directories chmod'd by a different task walk.","solutions":["Fix write permission/ownership on the directory containing config.json","Close any editors or processes holding the config file open and retry (Windows)","If config.json somehow became a directory, remove it and retry the save","Retry once — the temp file from the failed attempt is already cleaned up"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := cli.SaveCLIConfig(cfg); err != nil && strings.Contains(err.Error(), \"rename config file\") {\n\t// check directory writability and (on Windows) open handles, then retry\n}","preventionTips":["Ensure the config directory is writable by the saving user","On Windows, avoid holding config.json open while the CLI may write it","Rely on the atomic rename semantics: a failure never corrupts the existing file"],"tags":["filesystem","permissions","atomic-write","go"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}