hashicorp/nomad · warning
could not serialize our own error: %v
Error message
could not serialize our own error: %v
What it means
Fallback path in `writeJSON`: when `json.Marshal(obj)` fails, Nomad tries to marshal an errorWrapper containing the marshal error; if even that fails, this error is returned. This is nearly impossible in practice since errorWrapper is a simple string struct, and indicates an extreme internal problem (e.g. writer already broken and a pathological marshal failure).
Source
Thrown at command/operator_debug.go:1550
wrapped := errorWrapper{Error: apiErr.Error()}
return writeJSON(wrapped, writer)
}
err = writeNDJSON(obj, writer)
if err != nil {
return err
}
return nil
}
// writeNDJSON writes a single Nomad API objects (or response error) to the
// archive file as a JSON object.
func writeJSON(obj any, writer io.Writer) error {
buf, err := json.Marshal(obj)
if err != nil {
buf, err = json.Marshal(errorWrapper{Error: err.Error()})
if err != nil {
return fmt.Errorf("could not serialize our own error: %v", err)
}
}
n, err := writer.Write(buf)
if err != nil {
return fmt.Errorf("write error, wrote %d bytes of %d: %v", n, len(buf), err)
}
return nil
}
// writeNDJSON writes a slice of Nomad API objects to the archive file as
// newline-delimited JSON objects.
func writeNDJSON[T any](data []T, writer io.Writer) error {
for _, obj := range data {
err := writeJSON(obj, writer)
if err != nil {
return fmt.Errorf("failed to write to file: %w", err)
}
_, err = writer.Write([]byte{'\n'})View on GitHub (pinned to 482b49bf1a)
Solutions
- Verify you are running stock Nomad; a patched build may inject unserializable types into capture objects.
- Report upstream with the Nomad version and the debug command invocation.
- As a workaround, capture the failing API data via direct HTTP calls instead of the debug bundle.
- Check the wrapped %v message to identify the failing marshal reason.
Defensive patterns
Strategy: try-catch
Try / catch
if err := writeJSON(obj, w); err != nil {
if strings.Contains(err.Error(), "could not serialize our own error") {
// log the wrapped message, file an upstream bug with Nomad version
}
return err
} Prevention
- Run stock Nomad releases; patched builds may add unserializable fields to capture objects.
- Report this error upstream — it indicates an internal invariant violation.
- Keep the payload objects limited to documented Nomad API types.
When it happens
Trigger: json.Marshal of the payload object fails (e.g. unsupported type like a channel or func field, or a cyclic structure in an API response object), and the subsequent marshal of the errorWrapper also fails.
Common situations: A custom/patched Nomad build returning API objects with unserializable fields; writing objects that embed channels, funcs, or cycles; extremely unusual given all Nomad API types are serializable.
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
- error marshaling volume pramaters: %w
- failed to marshal json from Topic: %s, Type: %s, Err: %w
- write error, wrote %d bytes of %d: %v
- [✘] Role could not be interpolated with args: %w
- auth method could not be interpolated with args: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/ae6045d90dd36fee.
Report an issue: GitHub.