moonD4rk/HackBrowserData · error
encode dump: %w
Error message
encode dump: %w
What it means
WriteJSON failed to serialize the Dump struct to the supplied io.Writer via encoding/json. It fires at serialization time — an invalid writer (closed/nil), an io.Writer returning an error, or a Dump containing a value JSON cannot encode — and wraps the underlying json error for context. The Dump itself was already built; only the output step failed.
Source
Thrown at masterkey/dump.go:67
}
}
func currentHost() Host {
h := Host{OS: runtime.GOOS, Arch: runtime.GOARCH}
if name, err := os.Hostname(); err == nil {
h.Hostname = name
}
if u, err := user.Current(); err == nil {
h.User = u.Username
}
return h
}
func (d Dump) WriteJSON(w io.Writer) error {
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
if err := enc.Encode(d); err != nil {
return fmt.Errorf("encode dump: %w", err)
}
return nil
}
// ReadJSON parses a Dump and rejects any version this build can't interpret — a silent misparse of an
// unrecognized schema is worse than a clear error.
func ReadJSON(r io.Reader) (Dump, error) {
var d Dump
dec := json.NewDecoder(r)
if err := dec.Decode(&d); err != nil {
return Dump{}, fmt.Errorf("decode dump: %w", err)
}
if d.Version != DumpVersion {
return Dump{}, fmt.Errorf("unsupported dump version %q (this build expects %q)", d.Version, DumpVersion)
}
return d, nil
}
View on GitHub (pinned to 0503d04d7a)
Solutions
- Check the wrapped %w error to distinguish an I/O failure on the writer from an unencodable value.
- Ensure the destination writer is open and writable (file exists, disk has space, pipe peer alive).
- Confirm all fields of Dump (including any new vault kinds) are JSON-serializable types or have MarshalJSON implementations.
- Add a round-trip test (WriteJSON followed by ReadJSON) when adding new fields to Dump.
Defensive patterns
Strategy: try-catch
Validate before calling
buf := &bytes.Buffer{}
if err := dump.WriteJSON(buf); err != nil {
return fmt.Errorf("dump is not encodable: %w", err)
} Try / catch
if err := dump.WriteJSON(out); err != nil {
if errors.Is(err, syscall.EPIPE) {
log.Warnf("output pipe closed early: %v", err)
} else {
return fmt.Errorf("encode dump: %w", err)
}
} Prevention
- Write to a buffer first, then flush to the real sink, so encoding errors surface before I/O errors.
- Keep all Dump fields JSON-serializable; add MarshalJSON for custom vault kinds.
- Test the WriteJSON/ReadJSON round trip whenever Dump gains new fields.
When it happens
Trigger: Calling WriteJSON with a writer that fails mid-write (closed pipe, full disk, broken connection), or a Dump containing values json cannot encode (channels, funcs, cyclic data).
Common situations: Piping the dump into a process that exited early (broken pipe); writing to a full or read-only file/stdout; a Dump containing unmarshalable custom types added by a new VaultKind.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- write archive %s: %w
- abe: base64 decode: %w
- decode dump: %w
- unsupported dump version %q (this build expects %q)
- os_crypt.encrypted_key not found in Local State
AI-assisted analysis of moonD4rk/HackBrowserData@0503d04d7a (2026-09-06).
Data as JSON: /api/errors/018a1956a8b58e64.
Report an issue: GitHub.