{"record":{"id":"bbbfacbe2be2953e","repo":"sipeed/picoclaw","slug":"failed-to-write-temp-file-w","errorCode":null,"errorMessage":"failed to write temp file: %w","messagePattern":"failed to write temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fileutil/file.go","lineNumber":82,"sourceCode":"\t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create temp file: %w\", err)\n\t}\n\n\ttmpPath := tmpFile.Name()\n\tcleanup := true\n\n\tdefer func() {\n\t\tif cleanup {\n\t\t\ttmpFile.Close()\n\t\t\t_ = os.Remove(tmpPath)\n\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}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/fileutil/file.go#L64-L100","documentation":"Error \"failed to write temp file: %w\" thrown in sipeed/picoclaw.","triggerScenarios":"Thrown at pkg/fileutil/file.go:82 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"}