{"record":{"id":"a26ff23e0e60e060","repo":"moonD4rk/HackBrowserData","slug":"format-s-w","errorCode":null,"errorMessage":"format %s: %w","messagePattern":"format (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/output.go","lineNumber":139,"sourceCode":"\tvar s []categoryRows\n\tfor _, cat := range categories {\n\t\tvar rows []row\n\t\tfor _, r := range o.results {\n\t\t\trows = append(rows, cat.extract(r)...)\n\t\t}\n\t\tif len(rows) > 0 {\n\t\t\ts = append(s, categoryRows{cat.name, rows})\n\t\t}\n\t}\n\treturn s\n}\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","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/moonD4rk/HackBrowserData/blob/0503d04d7a8d0379d060268a74f1b149e5a0aad5/output/output.go#L121-L157","documentation":"Writer.writeFile first formats all rows into a buffer so no file is created when a formatter emits nothing (e.g. cookie-editor skipping non-cookie data). This error wraps a failure inside formatter.format for a given category, meaning the category's rows could not be serialized (encoding error inside the CSV/JSON/cookie-editor writer).","triggerScenarios":"o.formatter.format(&buf, rows) returned an error while writing rows for the named category — e.g. a csv.Writer.Flush error from unencodable data or an internal JSON encode failure.","commonSituations":"Row values containing characters the CSV writer rejects or that trigger encoding errors; a custom/injected formatter with a bug; extremely large row sets hitting memory limits; formatter state corrupted by a prior call.","solutions":["Inspect the wrapped %w cause to identify which formatter and which row failed.","Sanitize row values before extraction (valid UTF-8, no NUL bytes) so the CSV/JSON encoders succeed.","Update to the latest version in case a formatter encoding bug is fixed upstream.","If using a custom formatter implementation, test format() against your actual row data."],"exampleFix":"// before: raw bytes may not be valid UTF-8\nrows[i].value = string(rawBytes)\n// after\nrows[i].value = strings.ToValidUTF8(string(rawBytes), \"\\uFFFD\")","handlingStrategy":"try-catch","validationCode":"for _, r := range rows {\n\tfor _, v := range r.values {\n\t\tif !utf8.ValidString(v) { return fmt.Errorf(\"row %q has invalid UTF-8\", r.name) }\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := w.Write(); err != nil {\n\tif strings.Contains(err.Error(), \"format \") {\n\t\t// wrapped formatter failure: inspect %w cause, sanitize rows, retry\n\t}\n}","preventionTips":["Sanitize extracted values to valid UTF-8 before formatting.","Test custom formatter implementations against representative rows.","Keep the library updated for formatter bug fixes."],"tags":["output","formatting","csv","json"],"backgroundTag":"file-write-failed","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"}