{"record":{"id":"a38394c181c7eb8d","repo":"sipeed/picoclaw","slug":"failed-to-create-directory-w","errorCode":null,"errorMessage":"failed to create directory: %w","messagePattern":"failed to create directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fileutil/file.go","lineNumber":55,"sourceCode":"// Parameters:\n//   - path: Target file path\n//   - data: Data to write\n//   - perm: File permission mode (e.g., 0o600 for secure, 0o644 for readable)\n//\n// Returns:\n//   - Error if any step fails, nil on success\n//\n// Example:\n//\n//\t// Secure config file (owner read/write only)\n//\terr := utils.WriteFileAtomic(\"config.json\", data, 0o600)\n//\n//\t// Public readable file\n//\terr := utils.WriteFileAtomic(\"public.txt\", data, 0o644)\nfunc WriteFileAtomic(path string, data []byte, perm os.FileMode) error {\n\tdir := filepath.Dir(path)\n\tif err := os.MkdirAll(dir, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create directory: %w\", err)\n\t}\n\n\t// Create temp file in the same directory (ensures atomic rename works)\n\t// Using a hidden prefix (.tmp-) to avoid issues with some tools\n\ttmpFile, err := os.OpenFile(\n\t\tfilepath.Join(dir, fmt.Sprintf(\".tmp-%d-%d\", os.Getpid(), time.Now().UnixNano())),\n\t\tos.O_WRONLY|os.O_CREATE|os.O_EXCL,\n\t\tperm,\n\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 {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/fileutil/file.go#L37-L73","documentation":"Error \"failed to create directory: %w\" thrown in sipeed/picoclaw.","triggerScenarios":"Thrown at pkg/fileutil/file.go:55 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"}