{"record":{"id":"0cb09509b819d8c2","repo":"hashicorp/nomad","slug":"failed-to-marshal-json-from-topic-s-type-s-e","errorCode":null,"errorMessage":"failed to marshal json from Topic: %s, Type: %s, Err: %w","messagePattern":"failed to marshal json from Topic: (.+?), Type: (.+?), Err: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":986,"sourceCode":"\t\t\t\terrCount++\n\t\t\t\tc.verboseOutf(\"error from event stream: index; %d err: %v\", event.Index, event.Err)\n\t\t\t\tmErrs = multierror.Append(mErrs, fmt.Errorf(\"error at index: %d, Err: %w\", event.Index, event.Err))\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tif event.IsHeartbeat() {\n\t\t\t\theartbeatCount++\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfor _, e := range event.Events {\n\t\t\t\teventCount++\n\t\t\t\tc.verboseOutf(\"Event: %4d, Index: %d, Topic: %-10s, Type: %s, FilterKeys: %s\", eventCount, e.Index, e.Topic, e.Type, e.FilterKeys)\n\n\t\t\t\tbytes, err := json.Marshal(e)\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCount++\n\t\t\t\t\tmErrs = multierror.Append(mErrs, fmt.Errorf(\"failed to marshal json from Topic: %s, Type: %s, Err: %w\", e.Topic, e.Type, err))\n\t\t\t\t}\n\n\t\t\t\tn, err := fh.Write(bytes)\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCount++\n\t\t\t\t\tmErrs = multierror.Append(mErrs, fmt.Errorf(\"failed to write bytes to eventstream.json; bytes written: %d, Err: %w\", n, err))\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tn, err = fh.WriteString(\"\\n\")\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCount++\n\t\t\t\t\tmErrs = multierror.Append(mErrs, fmt.Errorf(\"failed to write string to eventstream.json; chars written: %d, Err: %w\", n, err))\n\t\t\t\t}\n\t\t\t}\n\t\tcase <-c.ctx.Done():\n\t\t\tc.verboseOutf(\"Event stream captured %d events, %d frames, %d heartbeats, %d errors\", eventCount, channelEventCount, heartbeatCount, errCount)\n\t\t\treturn mErrs.ErrorOrNil()\n\t\t}","sourceCodeStart":968,"sourceCodeEnd":1004,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L968-L1004","documentation":"For each non-error, non-heartbeat event, captureEventStream serializes the whole event struct with json.Marshal before writing it to eventstream.json. If marshaling fails, the event cannot be recorded and the failure is appended to the multierror with the event's Topic and Type. json.Marshal on well-formed event structs essentially only fails on unsupported channel/func/custom-marshaler values, so this usually indicates an unexpected event payload or a library-level serialization bug.","triggerScenarios":"json.Marshal(e) returns an error for a received event — e.g. an event type carrying a value its custom MarshalJSON rejects, or an internal field that cannot be represented in JSON.","commonSituations":"Capturing topics whose event payloads include exotic data; version mismatch between the CLI and the agent producing newer event fields with unsupported types; a bug in a custom MarshalJSON implementation.","solutions":["Record the Topic and Type in the message and check whether that topic's events changed with a recent Consul version — upgrade/downgrade the CLI to match the agent","Retry the capture; a single malformed frame loses only that event (errCount is tracked, loop continues)","Update the consul CLI to a version whose event types marshal cleanly for your agent version","If reproducible, report the unserializable Topic/Type upstream — this indicates a marshaling bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"bytes, err := json.Marshal(e)\nif err != nil {\n\terrs = multierror.Append(errs, fmt.Errorf(\"failed to marshal json from Topic: %s, Type: %s, Err: %w\", e.Topic, e.Type, err))\n\tcontinue // skip unserializable event, keep capture alive\n}","preventionTips":["Keep the consul CLI version aligned with the agent version","Note the failing Topic/Type and report persistent marshal failures upstream","Retry the capture — a single bad frame only loses that event"],"tags":["json","serialization","streaming"],"backgroundTag":"json-marshal-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}