{"record":{"id":"027c5a7f4243d1bd","repo":"sipeed/picoclaw","slug":"failed-to-rename-temp-file-w","errorCode":null,"errorMessage":"failed to rename temp file: %w","messagePattern":"failed to rename temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fileutil/file.go","lineNumber":106,"sourceCode":"\tif err := tmpFile.Sync(); err != nil {\n\t\treturn fmt.Errorf(\"failed to sync temp file: %w\", err)\n\t}\n\n\t// Set file permissions before closing\n\tif err := tmpFile.Chmod(perm); err != nil {\n\t\treturn fmt.Errorf(\"failed to set permissions: %w\", err)\n\t}\n\n\t// Close file before rename (required on Windows)\n\tif err := tmpFile.Close(); err != nil {\n\t\treturn fmt.Errorf(\"failed to close temp file: %w\", err)\n\t}\n\n\t// Atomic rename: temp file becomes the target\n\t// On POSIX: rename() is atomic\n\t// On Windows: Rename() is atomic for files\n\tif err := os.Rename(tmpPath, path); err != nil {\n\t\treturn fmt.Errorf(\"failed to rename temp file: %w\", err)\n\t}\n\n\t// Sync directory to ensure rename is durable\n\t// This prevents the renamed file from disappearing after a crash\n\tif dirFile, err := os.Open(dir); err == nil {\n\t\t_ = dirFile.Sync()\n\t\t_ = dirFile.Close()\n\t}\n\n\t// Success: skip cleanup (file was renamed, no temp to remove)\n\tcleanup = false\n\treturn nil\n}\n\nfunc CopyFile(src, dst string, perm os.FileMode) error {\n\tdata, err := os.ReadFile(src)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/fileutil/file.go#L88-L124","documentation":"Error \"failed to rename temp file: %w\" thrown in sipeed/picoclaw.","triggerScenarios":"Thrown at pkg/fileutil/file.go:106 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}