moonD4rk/HackBrowserData · error
format %s: %w
Error message
format %s: %w
What it means
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).
Source
Thrown at output/output.go:139
var s []categoryRows
for _, cat := range categories {
var rows []row
for _, r := range o.results {
rows = append(rows, cat.extract(r)...)
}
if len(rows) > 0 {
s = append(s, categoryRows{cat.name, rows})
}
}
return s
}
func (o *Writer) writeFile(category string, rows []row) (err error) {
// Format to buffer first — if formatter produces no output (e.g.
// cookie-editor skipping non-cookie data), don't create the file.
var buf bytes.Buffer
if err := o.formatter.format(&buf, rows); err != nil {
return fmt.Errorf("format %s: %w", category, err)
}
if buf.Len() == 0 {
return nil
}
filename := fmt.Sprintf("%s.%s", category, o.formatter.ext())
path := filepath.Join(o.dir, filename)
f, err := os.OpenFile(filepath.Clean(path), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
if err != nil {
return fmt.Errorf("create %s: %w", filename, err)
}
defer func() {
if cerr := f.Close(); cerr != nil && err == nil {
err = fmt.Errorf("close %s: %w", filename, cerr)
}
}()
View on GitHub (pinned to 0503d04d7a)
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.
Example fix
// before: raw bytes may not be valid UTF-8 rows[i].value = string(rawBytes) // after rows[i].value = strings.ToValidUTF8(string(rawBytes), "\uFFFD")
Defensive patterns
Strategy: try-catch
Validate before calling
for _, r := range rows {
for _, v := range r.values {
if !utf8.ValidString(v) { return fmt.Errorf("row %q has invalid UTF-8", r.name) }
}
} Try / catch
if err := w.Write(); err != nil {
if strings.Contains(err.Error(), "format ") {
// wrapped formatter failure: inspect %w cause, sanitize rows, retry
}
} Prevention
- Sanitize extracted values to valid UTF-8 before formatting.
- Test custom formatter implementations against representative rows.
- Keep the library updated for formatter bug fixes.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- write BOM: %w
- abe: base64 decode: %w
- encode dump: %w
- decode dump: %w
- unsupported dump version %q (this build expects %q)
AI-assisted analysis of moonD4rk/HackBrowserData@0503d04d7a (2026-09-06).
Data as JSON: /api/errors/a26ff23e0e60e060.
Report an issue: GitHub.