{"record":{"id":"05acb3f6ac2d78a8","repo":"sipeed/picoclaw","slug":"failed-to-set-permissions-w","errorCode":null,"errorMessage":"failed to set permissions: %w","messagePattern":"failed to set permissions: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fileutil/file.go","lineNumber":94,"sourceCode":"\t\t}\n\t}()\n\n\t// Write data to temp file\n\t// Note: Original file is untouched at this point\n\tif _, err := tmpFile.Write(data); err != nil {\n\t\treturn fmt.Errorf(\"failed to write temp file: %w\", err)\n\t}\n\n\t// CRITICAL: Force sync to storage medium before any other operations.\n\t// This ensures data is physically written to disk, not just cached.\n\t// Essential for SD cards, eMMC, and other flash storage on edge devices.\n\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()","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/fileutil/file.go#L76-L112","documentation":"Error \"failed to set permissions: %w\" thrown in sipeed/picoclaw.","triggerScenarios":"Thrown at pkg/fileutil/file.go:94 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"}