moonD4rk/HackBrowserData · error
write BOM: %w
Error message
write BOM: %w
What it means
For CSV output, writeFile writes a 3-byte UTF-8 BOM before the formatted content so Excel detects UTF-8. This error wraps a failed f.Write of that BOM, meaning even the first bytes of the file could not be written — the output file will be missing or invalid.
Source
Thrown at output/output.go:160
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)
}
}()
if strings.HasSuffix(path, ".csv") {
if _, err := f.Write(utf8BOM); err != nil {
return fmt.Errorf("write BOM: %w", err)
}
}
if _, err := f.Write(buf.Bytes()); err != nil {
return fmt.Errorf("write %s: %w", filename, err)
}
return nil
}
View on GitHub (pinned to 0503d04d7a)
Solutions
- Free disk space on the output volume and retry.
- Write output to a reliable local filesystem rather than network/removable mounts.
- Verify the file handle is valid (no early Close) and re-run the extraction.
- Check container/volume size limits if writing into tmpfs or small volumes.
Example fix
// before
if _, err := f.Write(utf8BOM); err != nil {
return fmt.Errorf("write BOM: %w", err)
}
// after: check the short-write case explicitly
if n, err := f.Write(utf8BOM); err != nil || n != len(utf8BOM) {
return fmt.Errorf("write BOM: wrote %d bytes: %w", n, err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if st, err := os.Stat(outputDir); err == nil {
_ = st // also verify volume free space > expected output size before writing
} Try / catch
if err := w.Write(); err != nil {
if strings.Contains(err.Error(), "write BOM") {
// handle write failed immediately after open: check disk/handle, retry
}
} Prevention
- Monitor disk space; fail fast before extraction on low space.
- Avoid tmpfs/small volumes for output.
- Keep the output path on stable local storage.
- Handle short writes explicitly in custom write paths.
When it happens
Trigger: f.Write(utf8BOM) returned a short write or error right after a successful OpenFile: disk full, handle closed/invalid, or the file descriptor became unwritable between open and write.
Common situations: Disk filled between file creation and write; file opened on a flaky network/USB volume; extremely constrained environments (containers with tiny tmpfs output dirs).
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
AI-assisted analysis of moonD4rk/HackBrowserData@0503d04d7a (2026-09-06).
Data as JSON: /api/errors/22ade0da87f65fa5.
Report an issue: GitHub.