{"record":{"id":"a9464c58b28792ce","repo":"swc-project/swc","slug":"failed-to-serialize-json","errorCode":null,"errorMessage":"failed to serialize json: {}","messagePattern":"failed to serialize json: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/binding_macros/src/wasm.rs","lineNumber":271,"sourceCode":"                    .map_err(|e| $crate::wasm::anyhow::anyhow!(\"failed to deserialize program: {}\", e))?;\n                  let s = $crate::wasm::anyhow::Context::context(c\n                    .print(\n                        &program,\n                        PrintArgs {\n                          inline_sources_content: true,\n                          source_map: opts.source_maps\n                              .clone()\n                              .unwrap_or($crate::wasm::SourceMapsConfig::Bool(false)),\n                          emit_source_map_columns: opts.config.emit_source_map_columns.into_bool(),\n                          codegen_config: swc_core::ecma::codegen::Config::default()\n                              .with_target(opts.codegen_target().unwrap_or($crate::wasm::EsVersion::Es2020))\n                              .with_minify(opts.config.minify.into()),\n                          ..Default::default()\n                        },\n                    ),\"failed to print code\")?;\n\n                    serde_wasm_bindgen::to_value(&s)\n                    .map_err(|e| anyhow::anyhow!(\"failed to serialize json: {}\", e))\n              })\n          },\n      )\n      .map_err(|e| $crate::wasm::convert_err(e, None))\n    }\n  };\n}\n\n/// Currently this relies on existence of print_sync.\n#[macro_export]\nmacro_rules! build_print {\n  ($(#[$m:meta])*) => {\n    build_print!($(#[$m])*, Default::default());\n  };\n  ($(#[$m:meta])*, $opt: expr) => {\n\n      $(#[$m])*\n      pub fn print(s: $crate::wasm::JsValue, opts: $crate::wasm::JsValue) -> $crate::wasm::js_sys::Promise {","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/binding_macros/src/wasm.rs#L253-L289","documentation":"Emitted by the build_print_sync wasm macro after printing succeeded, when serde_wasm_bindgen::to_value fails to convert the printed output (code + optional source map object) into a JsValue. Printing itself worked; only the final JS-value conversion failed - an internal, very rare binding failure.","triggerScenarios":"Serializer limitations on the output struct for specific binding versions; wasm memory exhaustion while building the result JsValue for very large outputs with inline source maps.","commonSituations":"Very large printed bundles in constrained wasm environments; version-transition bugs in the wasm print binding.","solutions":["Disable source maps (sourceMaps: false) or print smaller inputs to rule out memory pressure","Upgrade the wasm binding; to_value failures around version bumps are fixed upstream","Report with the {e} detail and a repro if current versions still fail"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const out = printSync(program, opts);\n} catch (e) {\n  if (String(e).startsWith('failed to serialize json')) {\n    reportInternal(e, { programSize }); // include {e} detail in the report\n  }\n  throw e;\n}","preventionTips":["Print without source maps when outputs are near wasm memory limits","Treat this error as a binding bug: always capture version + options for the upstream report"],"tags":["wasm","print","serialization","internal-error"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}