{"record":{"id":"41844e2f794c4dbe","repo":"swc-project/swc","slug":"should-able-to-deserialize","errorCode":null,"errorMessage":"Should able to deserialize","messagePattern":"Should able to deserialize","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/swc_plugin_runner/src/imported_fn/metadata_context.rs","lineNumber":103,"sourceCode":"    };\n    let value = VersionedSerializable::new(value);\n    let serialized = PluginSerializedBytes::try_serialize(&value).expect(\"Should be serializable\");\n\n    allocate_return_values_into_guest(caller, allocated_ret_ptr, &serialized);\n\n    1\n}\n\n#[cfg_attr(debug_assertions, tracing::instrument(level = \"info\", skip_all))]\npub fn get_experimental_transform_context(\n    caller: &mut dyn runtime::Caller<'_>,\n    env: &MetadataContextHostEnvironment,\n    allocated_ret_ptr: u32,\n) -> i32 {\n    let context_key_buffer = env.mutable_context_key_buffer.lock();\n    let key: String = PluginSerializedBytes::from_bytes(context_key_buffer.clone())\n        .deserialize()\n        .expect(\"Should able to deserialize\")\n        .into_inner();\n\n    let value = env\n        .metadata_context\n        .experimental\n        .get(&key)\n        .map(|v| v.to_string());\n\n    if let Some(value) = value {\n        let serialized = PluginSerializedBytes::try_serialize(&VersionedSerializable::new(value))\n            .expect(\"Should be serializable\");\n\n        allocate_return_values_into_guest(caller, allocated_ret_ptr, &serialized);\n\n        return 1;\n    }\n\n    0","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_plugin_runner/src/imported_fn/metadata_context.rs#L85-L121","documentation":"Host import `get_experimental_transform_context`: it decodes the key that the plugin previously wrote into `mutable_context_key_buffer` from versioned CBOR into a String; decode failure panics. Unlike the pure host-side encodes, the input here is guest-produced, so a plugin that writes the key with mismatched bindings (different swc_core schema), writes nothing, or corrupts the buffer makes this panic reachable.","triggerScenarios":"A plugin calls get_experimental_transform_context after writing a key buffer whose bytes are not the expected versioned CBOR String - typically because the plugin's swc_core predates/postdates the host runner's wire format, or it skipped writing the key.","commonSituations":"Experimental-context plugin APIs used across an @swc/core upgrade; plugin binaries compiled with a different swc_core minor; bugs in custom plugins that mismanage the key buffer.","solutions":["Rebuild the plugin against the swc_core version matching the installed @swc/core","Upgrade @swc/core and the plugin atomically","If you own the plugin, ensure it sets the context key through the generated bindings instead of manual memory writes","Report upstream with the plugin source if matched versions still fail"],"exampleFix":"# before\n# host @swc/core new, plugin wasm old -> guest writes legacy key encoding\n\n# after\ncargo update -p swc_core --precise <host-matching version>\ncargo build-wasi --release","handlingStrategy":"validation","validationCode":"// before enabling experimental context features, assert matched versions\nif (usesExperimentalContext(plugin)) {\n  assertPluginHostAligned(plugin, coreVersion);\n}","typeGuard":null,"tryCatchPattern":"// the deserialization panic crosses FFI and aborts Node; contain it in a child process:\nawait execFile(node, ['plugin-job.js']).catch(e => { throw new Error(`experimental context decode failed: ${e}`); });","preventionTips":["Avoid experimental plugin APIs on mixed versions","If authoring plugins, use generated bindings for context keys instead of manual writes","Pin exact @swc/core versions while experimental features are in play"],"tags":["plugin","wasm","cbor","deserialization","metadata","version-mismatch","panic"],"backgroundTag":"plugin-host-version-mismatch","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}