juanfont/headscale · warning
marshaling expected online map: %w
Error message
marshaling expected online map: %w
What it means
json.MarshalIndent failed while serializing the expected online map built by integrationutil.BuildExpectedOnlineMap. Marshal only fails on unserializable Go values (channels, functions, cycles in the older encoder, +Inf/NaN floats, unsupported map key types). The expected map is built from parsed MapResponse data, so in practice this error is nearly unreachable — it would indicate a schema regression where an unsupported type leaked into the expected structure.
Source
Thrown at cmd/mapresponses/main.go:59
command.RunOrFail(env, os.Args[1:])
}
// runIntegrationTest executes the integration test workflow.
func runOnline(env *command.Env) error {
if mapConfig.Directory == "" {
return errDirectoryRequired
}
resps, err := mapper.ReadMapResponsesFromDirectory(mapConfig.Directory)
if err != nil {
return fmt.Errorf("reading map responses from directory: %w", err)
}
expected := integrationutil.BuildExpectedOnlineMap(resps)
out, err := json.MarshalIndent(expected, "", " ")
if err != nil {
return fmt.Errorf("marshaling expected online map: %w", err)
}
os.Stderr.Write(out)
os.Stderr.Write([]byte("\n"))
return nil
}
View on GitHub (pinned to 565fd254d0)
Solutions
- Treat it as a code defect: inspect what BuildExpectedOnlineMap produced (add a temporary debug print of the struct types)
- Verify any newly added fields on the expected-map types are JSON-marshalable (no func/chan, json tags present)
- If NaN floats can occur in captures, sanitize them to nil before building the expected map
Defensive patterns
Strategy: try-catch
Try / catch
out, err := json.MarshalIndent(expected, "", " ")
if err != nil {
// practically unreachable for plain structs; if hit, log the type that broke marshaling
log.Printf("marshal failed: %v", err)
return err
} Prevention
- Keep expected-map structs limited to JSON-marshalable fields (no func/chan)
- Sanitize NaN/Inf floats from captured data before building the expected map
- Treat this error as a signal of a schema bug, not a data problem
When it happens
Trigger: BuildExpectedOnlineMap output containing a func/chan field, a map with a non-string/comparable-but-unsupported key, or NaN/Inf float values produced by degenerate capture data.
Common situations: Practically never in normal operation; only after introducing new field types into the expected-map structs without json tags or with unsupported underlying types.
Related errors
- reading map responses from directory: %w
- failed to convert node interface
- type not supported
- invalid group member type
- group value must be an array of users
AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15).
Data as JSON: /api/errors/0180e98ba2956186.
Report an issue: GitHub.