{"record":{"id":"832610f97f9e5252","repo":"BoundaryML/baml","slug":"packageinterface-artifact-serialization-into-vec-is","errorCode":null,"errorMessage":"PackageInterface artifact serialization into Vec is infallible","messagePattern":"PackageInterface artifact serialization into Vec is infallible","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_compiler2_emit/src/lib.rs","lineNumber":420,"sourceCode":"            let root = file_package(db, *file).root;\n            (spelling.of(root).clone(), root)\n        })\n        .collect();\n    packages\n        .into_iter()\n        .map(|(package_name, package)| {\n            let interface =\n                baml_compiler2_hir_ty::package_interface::package_interface(db, package);\n            // Runtime compilers already own the exact stdlib sources, so only\n            // mountable packages need to carry a serialized compiler surface.\n            let interface_blob = if package.kind(db) == baml_base::SourceRootKind::Stdlib {\n                Vec::new()\n            } else {\n                baml_artifact::encode(\n                    baml_artifact::ArtifactKind::PackageInterface,\n                    &baml_compiler2_hir_ty::package_interface::export_interface(db, package),\n                )\n                .expect(\"PackageInterface artifact serialization into Vec is infallible\")\n            };\n            let functions = interface\n                .functions\n                .iter()\n                .flat_map(|(namespace, functions)| {\n                    functions.iter().map(|(name, function)| {\n                        (\n                            bex_vm_types::types::LocalName {\n                                namespace: namespace.clone(),\n                                name: name.clone(),\n                            },\n                            external_call_target_name(spelling, &function.target),\n                        )\n                    })\n                })\n                .collect::<Vec<_>>();\n            let exported_names = interface\n                .types","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/lib.rs#L402-L438","documentation":"When capturing package exports, the compiler serializes a `PackageInterface` artifact with `baml_artifact::encode` and `.expect`s success, asserting that encoding a PackageInterface artifact into a `Vec<u8>` cannot fail. The panic means the encoder returned an error for this artifact kind — typically an unsupported kind registration, an internal serialization fault, or an IO sink failure if the encode API can fail.","triggerScenarios":"Calling `capture_package_exports` (via `generate_impl`) when `baml_artifact::encode` returns Err for `ArtifactKind::PackageInterface` — e.g., a codec mismatch between artifact versions or a non-in-memory sink error.","commonSituations":"Version skew between crates after an artifact-format change; registering/failing the PackageInterface encoder; corrupted or incompatible build cache inputs.","solutions":["Check that `baml_artifact::encode` supports `ArtifactKind::PackageInterface` and that the interface payload implements the required serialization trait","Clean rebuild / clear stale build artifacts to remove version-skew between baml_artifact and the compiler crates","Update all baml compiler crates together so artifact codecs match","If encode can legitimately fail, propagate the error instead of expecting"],"exampleFix":"// before\n.expect(\"PackageInterface artifact serialization into Vec is infallible\")\n// after\n.map_err(|e| EmitError::ArtifactSerialization(e))?","handlingStrategy":"try-catch","validationCode":"// ensure encode supports the kind and payload before calling\ndebug_assert!(baml_artifact::supports_kind(ArtifactKind::PackageInterface));","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| capture_package_exports(db, package))\n    .unwrap_or_else(|_| report_compiler_bug(\"PackageInterface serialization failed\"));","preventionTips":["Keep baml_artifact and compiler crates on matching versions (rebuild together)","Add a unit test that round-trips a PackageInterface artifact through encode/decode","Clear stale build caches after artifact-format changes"],"tags":["compiler","rust","panic","serialization","artifacts"],"backgroundTag":"json-serialization-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}