{"record":{"id":"fc7b57621c8ea9fd","repo":"moonD4rk/HackBrowserData","slug":"create-output-dir-w","errorCode":null,"errorMessage":"create output dir: %w","messagePattern":"create output dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/output.go","lineNumber":61,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn &Writer{dir: dir, formatter: f}, nil\n}\n\n// Add accumulates one browser profile's data for later writing.\nfunc (o *Writer) Add(browser, profile string, data *types.BrowserData) {\n\tif data == nil {\n\t\treturn\n\t}\n\to.results = append(o.results, result{browser, profile, data})\n}\n\n// Write aggregates all accumulated data by category and writes each\n// non-empty category to its own file (e.g. password.csv, cookie.json).\nfunc (o *Writer) Write() error {\n\tif err := os.MkdirAll(o.dir, 0o750); err != nil {\n\t\treturn fmt.Errorf(\"create output dir: %w\", err)\n\t}\n\tagg := o.aggregate()\n\tfor _, cs := range agg {\n\t\tif err := o.writeFile(cs.name, cs.rows); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tif len(agg) > 0 {\n\t\tfmt.Fprintln(os.Stderr)\n\t\tlog.Infof(\"Exported to %s/\", o.dir)\n\t\tfor _, cs := range agg {\n\t\t\tfilename := fmt.Sprintf(\"%s.%s\", cs.name, o.formatter.ext())\n\t\t\tlog.Infof(\"  %-24s %d entries\", filename, len(cs.rows))\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/moonD4rk/HackBrowserData/blob/0503d04d7a8d0379d060268a74f1b149e5a0aad5/output/output.go#L43-L79","documentation":"Writer.Write creates the output directory (os.MkdirAll, mode 0750) before writing per-category files like password.csv. This error wraps the MkdirAll failure, meaning no output could be written because the destination directory could not be created (or, for an existing path, is not a directory).","triggerScenarios":"os.MkdirAll(o.dir, 0o750) failed: parent directories missing/unwritable, disk full, the target path exists as a regular file, or the process lacks permission at that location.","commonSituations":"Output dir set to a read-only location or another user's home; a file already exists at the output path; running on a read-only mounted volume or full disk; invalid path characters/overly long paths on Windows; sandboxed/CI environments restricting writes.","solutions":["Choose a writable output directory (e.g. project dir or user temp) and pass that to NewWriter.","Check whether a file occupies the output path and remove/rename it.","Verify permissions on the parent directory (write + execute bits) and free disk space.","Run the process with sufficient privileges or use os.Getwd()/os.UserCacheDir() as a fallback location."],"exampleFix":"// before: fixed system path may not be writable\nw, _ := output.NewWriter(\"/var/secure-out\", \"csv\", nil)\n// after: fall back to a writable dir\nif _, err := os.Stat(\"/var/secure-out\"); err != nil {\n\tdir, _ = os.MkdirTemp(\"\", \"hbd-out\")\n}\nw, _ := output.NewWriter(dir, \"csv\", nil)","handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(dir); err == nil && !fi.IsDir() {\n\treturn fmt.Errorf(\"output path %s is a file\", dir)\n}\nprobe := filepath.Join(dir, \".probe\")\nif err := os.WriteFile(probe, nil, 0o600); err != nil {\n\treturn fmt.Errorf(\"output dir not writable: %w\", err)\n}\nos.Remove(probe)","typeGuard":"func isWritableDir(path string) bool {\n\tfi, err := os.Stat(path)\n\treturn err == nil && fi.IsDir() || os.IsNotExist(err)\n}","tryCatchPattern":"if err := w.Write(); err != nil {\n\tvar pe *fs.PathError\n\tif errors.As(err, &pe) && strings.Contains(err.Error(), \"create output dir\") {\n\t\t// switch to fallback dir and retry\n\t}\n}","preventionTips":["Default output to a guaranteed-writable dir (cwd or os.MkdirTemp).","Ensure the path isn't an existing regular file.","Check disk space and mount ro/rw status before runs.","In CI, grant the runner write access to the output location."],"tags":["filesystem","output","directory","windows","linux","macos"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"0503d04d7a8d0379d060268a74f1b149e5a0aad5","analyzedAt":"2026-09-06T13:38:28.707Z","contentChangedAt":"2026-09-06T13:38:28.707Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}