swc-project/swc · error
json subdiagnostic: {d:?}
Error message
json subdiagnostic: {d:?} What it means
An unreachable!() in the JSON diagnostic emit path (binding_nodejs_support_wasm lib.rs:173). While serializing a top-level diagnostic's sub-diagnostics (children), the code maps each child; the arm is reached only if the child list yields something the mapping code considers impossible for well-formed diagnostics from rustc/swc — i.e. a malformed sub-diagnostic structure. It marks a broken invariant in diagnostic construction rather than a user input error, and names the offending sub-diagnostic via {d:?}.
Source
Thrown at bindings/binding_nodejs_support_wasm/src/lib.rs:173
let snippet = d.span.primary_span().and_then(|span| {
let mut snippet = String::new();
let reporter = self.reporter.get_or_insert_with(json_reporter);
match reporter.render_report(
&mut snippet,
&Snippet {
source_code: &to_pretty_source_code(&self.cm, true),
span,
},
) {
Ok(()) => Some(snippet),
Err(_) => None,
}
});
let children = d
.children
.iter()
.map(|d| todo!("json subdiagnostic: {d:?}"))
.collect::<Vec<_>>();
let error_code = match &d.code {
Some(DiagnosticId::Error(s)) => Some(&**s),
Some(DiagnosticId::Lint(s)) => Some(&**s),
None => None,
};
let start = d
.span
.primary_span()
.and_then(|span| self.cm.try_lookup_char_pos(span.lo()).ok());
let end = d
.span
.primary_span()
.and_then(|span| self.cm.try_lookup_char_pos(span.hi()).ok());
View on GitHub (pinned to 5176682b65)
Solutions
- Log the full parent diagnostic to see which sub-diagnostic shape broke the invariant
- Ensure diagnostics are constructed via the swc_common diagnostic builders so children are always well-formed
- Return an error from emit instead of panicking so the wasm binding can surface a JS-side failure
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at bindings/binding_nodejs_support_wasm/src/lib.rs:173 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/0b2e121b6302d534.
Report an issue: GitHub.