{"record":{"id":"bb2583e230e5edd4","repo":"moonD4rk/HackBrowserData","slug":"create-s-w","errorCode":null,"errorMessage":"create %s: %w","messagePattern":"create (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/output.go","lineNumber":150,"sourceCode":"}\n\nfunc (o *Writer) writeFile(category string, rows []row) (err error) {\n\t// Format to buffer first — if formatter produces no output (e.g.\n\t// cookie-editor skipping non-cookie data), don't create the file.\n\tvar buf bytes.Buffer\n\tif err := o.formatter.format(&buf, rows); err != nil {\n\t\treturn fmt.Errorf(\"format %s: %w\", category, err)\n\t}\n\tif buf.Len() == 0 {\n\t\treturn nil\n\t}\n\n\tfilename := fmt.Sprintf(\"%s.%s\", category, o.formatter.ext())\n\tpath := filepath.Join(o.dir, filename)\n\n\tf, err := os.OpenFile(filepath.Clean(path), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create %s: %w\", filename, err)\n\t}\n\tdefer func() {\n\t\tif cerr := f.Close(); cerr != nil && err == nil {\n\t\t\terr = fmt.Errorf(\"close %s: %w\", filename, cerr)\n\t\t}\n\t}()\n\n\tif strings.HasSuffix(path, \".csv\") {\n\t\tif _, err := f.Write(utf8BOM); err != nil {\n\t\t\treturn fmt.Errorf(\"write BOM: %w\", err)\n\t\t}\n\t}\n\n\tif _, err := f.Write(buf.Bytes()); err != nil {\n\t\treturn fmt.Errorf(\"write %s: %w\", filename, err)\n\t}\n\treturn nil\n}","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/moonD4rk/HackBrowserData/blob/0503d04d7a8d0379d060268a74f1b149e5a0aad5/output/output.go#L132-L168","documentation":"After formatting succeeds, writeFile opens the destination file (category.ext) inside the output dir with O_CREATE|O_WRONLY|O_TRUNC and mode 0600. This error wraps os.OpenFile failure, meaning the result file could not be created or truncated in the output directory.","triggerScenarios":"os.OpenFile(filepath.Clean(path), ...) failed: permission denied in o.dir, the path exists as a directory, disk full, too many open files, or filename invalid for the platform (reserved names like 'con.csv' on Windows, over-long paths).","commonSituations":"Output directory became read-only after creation; antivirus/EDR blocking creation of files like password.csv; Windows reserved device names; category name containing path-hostile characters; file locked by another process (e.g. an editor or spreadsheet holding the CSV open).","solutions":["Check permissions and ownership of the output directory; pick a different dir if restricted.","Close any program holding the target file open (Excel/editors lock CSVs on Windows).","Rename output dir/file if it collides with Windows reserved names or path-length limits; use a shorter output dir.","Exclude/whitelist the output directory in security software if it blocks file creation.","Check ulimit -n (too many open files) if running in a long-lived process."],"exampleFix":"// before\nf, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)\n// after: surface a clearer failure and retry once in temp dir\nf, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)\nif err != nil {\n\ttmp, terr := os.CreateTemp(\"\", category+\"-*.\"+ext)\n\tif terr != nil { return fmt.Errorf(\"create %s: %w\", filename, err) }\n\tf = tmp\n}","handlingStrategy":"validation","validationCode":"if err := unix.Access(dir, unix.W_OK); err != nil { return fmt.Errorf(\"dir not writable: %v\", err) } // or attempt a probe file\ndummy := filepath.Join(dir, \".write-test\")\nif err := os.WriteFile(dummy, nil, 0o600); err != nil { return err }\nos.Remove(dummy)","typeGuard":"func canCreateIn(dir string) bool {\n\tf, err := os.CreateTemp(dir, \".probe-*\")\n\tif err != nil { return false }\n\tf.Close(); os.Remove(f.Name())\n\treturn true\n}","tryCatchPattern":"if err := w.Write(); err != nil {\n\tvar pe *fs.PathError\n\tif errors.As(err, &pe) && errors.Is(err, fs.ErrPermission) {\n\t\t// pick another output dir or elevate\n\t}\n}","preventionTips":["Avoid Windows reserved filenames and very long output paths.","Don't keep target CSVs open in Excel during a run.","Whitelist the output dir in AV/EDR policies.","Monitor open-file limits in long-running processes."],"tags":["filesystem","output","file-write","permission"],"backgroundTag":"file-write-permission-denied","analyzedSha":"0503d04d7a8d0379d060268a74f1b149e5a0aad5","analyzedAt":"2026-09-06T13:38:28.707Z","contentChangedAt":"2026-09-06T13:38:28.707Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}