dbt-labs/dbt-core · error
Failed to serialize core event info to JSON
Error message
Failed to serialize core event info to JSON
What it means
The JSON compat layer builds a dbt-core-style CoreEventInfo struct for a progress/log event and converts it with serde_json::to_value, unwrapping via .expect. Panicking here means serde_json could not serialize the struct, an internal invariant violation since all CoreEventInfo fields are plain strings/ints plus an `extra` map of custom env values.
Source
Thrown at crates/dbt-common/src/tracing/layers/json_compat_layer.rs:1085
// In debug build panic for unknown codes to catch missing mappings, in prod just skip
#[cfg(debug_assertions)]
panic!(
"Unhandled dbt_core_event_code '{}' in ProgressMessage. Add mapping in JsonCompatLayer `emit_progress_message` function.",
progress_msg.dbt_core_event_code.as_deref().unwrap()
);
#[cfg(not(debug_assertions))]
return;
}
None => (None, None), // Fall back to generic handling
};
let info_json = serde_json::to_value(self.build_core_event_info(
event_code,
event_name,
&log_record.severity_text,
msg.clone(),
))
.expect("Failed to serialize core event info to JSON");
let mut data_obj = json!({
"msg": msg,
});
// Include unique_id in node_info if available
if let Some(unique_id) = progress_msg.unique_id.as_deref() {
data_obj.as_object_mut().unwrap().insert(
"node_info".to_string(),
json!({
"unique_id": unique_id
}),
);
}
let value = json!({
"info": info_json,
"data": data_objView on GitHub (pinned to 0267ce9170)
Solutions
- Inspect the custom envs fed to JsonCompatLayer and ensure they are JSON-safe values (string keys, no NaN/Infinity)
- Replace the .expect with graceful handling that logs the event without the info block instead of aborting the run
- Reproduce with RUST_BACKTRACE=1 and check which CoreEventInfo field fails; fix the type at the source
Example fix
// before
let info_json = serde_json::to_value(self.build_core_event_info(
event_code,
event_name,
&log_record.severity_text,
msg.clone(),
))
.expect("Failed to serialize core event info to JSON");
// after
let info_json = serde_json::to_value(self.build_core_event_info(
event_code,
event_name,
&log_record.severity_text,
msg.clone(),
))
.unwrap_or(serde_json::Value::Null); Defensive patterns
Strategy: fallback
Validate before calling
fn is_json_safe(v: &serde_json::Value) -> bool {
use serde_json::Value;
match v {
Value::Null | Value::Bool(_) | Value::String(_) | Value::Number(_) => true,
Value::Array(a) => a.iter().all(is_json_safe),
Value::Object(m) => m.iter().all(|(_k, v)| is_json_safe(v)),
}
}
// assert every custom env value is_json_safe before constructing JsonCompatLayer Try / catch
let info_json = serde_json::to_value(info).unwrap_or(serde_json::Value::Null);
Prevention
- Only pass JSON-serializable custom env values (string keys, finite numbers) to the tracing layer
- Add a round-trip unit test serializing CoreEventInfo in CI
- Prefer unwrap_or(Value::Null) + warn over .expect in logging hot paths
When it happens
Trigger: on_log_record -> emit_progress_message runs while the JSON compat layer is active (json/machine output format) and the CoreEventInfo payload fails to serialize — practically only when a custom env entry injected into `extra` is not JSON-representable (non-string map key or non-finite float like NaN) or struct invariants are broken by a code change.
Common situations: Running dbt with --log-format json / machine output in CI; injecting custom env vars for log enrichment containing non-finite floats or exotic types; upgrading dbt-common after touching the tracing code.
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
- Parent span must have a SpanStartInfo record in its extensio
- Parquet writer is not initialized
- Failed to convert value to JSON: {err}
- invalid serialized time precision
- invalid serialized timestamp precision
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/fba2eba8a70b9769.
Report an issue: GitHub.