{"record":{"id":"018a1956a8b58e64","repo":"moonD4rk/HackBrowserData","slug":"encode-dump-w","errorCode":null,"errorMessage":"encode dump: %w","messagePattern":"encode dump: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"masterkey/dump.go","lineNumber":67,"sourceCode":"\t}\n}\n\nfunc currentHost() Host {\n\th := Host{OS: runtime.GOOS, Arch: runtime.GOARCH}\n\tif name, err := os.Hostname(); err == nil {\n\t\th.Hostname = name\n\t}\n\tif u, err := user.Current(); err == nil {\n\t\th.User = u.Username\n\t}\n\treturn h\n}\n\nfunc (d Dump) WriteJSON(w io.Writer) error {\n\tenc := json.NewEncoder(w)\n\tenc.SetIndent(\"\", \"  \")\n\tif err := enc.Encode(d); err != nil {\n\t\treturn fmt.Errorf(\"encode dump: %w\", err)\n\t}\n\treturn nil\n}\n\n// ReadJSON parses a Dump and rejects any version this build can't interpret — a silent misparse of an\n// unrecognized schema is worse than a clear error.\nfunc ReadJSON(r io.Reader) (Dump, error) {\n\tvar d Dump\n\tdec := json.NewDecoder(r)\n\tif err := dec.Decode(&d); err != nil {\n\t\treturn Dump{}, fmt.Errorf(\"decode dump: %w\", err)\n\t}\n\tif d.Version != DumpVersion {\n\t\treturn Dump{}, fmt.Errorf(\"unsupported dump version %q (this build expects %q)\", d.Version, DumpVersion)\n\t}\n\treturn d, nil\n}\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/moonD4rk/HackBrowserData/blob/0503d04d7a8d0379d060268a74f1b149e5a0aad5/masterkey/dump.go#L49-L85","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"buf := &bytes.Buffer{}\nif err := dump.WriteJSON(buf); err != nil {\n\treturn fmt.Errorf(\"dump is not encodable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := dump.WriteJSON(out); err != nil {\n\tif errors.Is(err, syscall.EPIPE) {\n\t\tlog.Warnf(\"output pipe closed early: %v\", err)\n\t} else {\n\t\treturn fmt.Errorf(\"encode dump: %w\", err)\n\t}\n}","preventionTips":["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."],"tags":["json","serialization","io"],"backgroundTag":"json-marshal-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"}