{"record":{"id":"451a31520dccc5fc","repo":"BoundaryML/baml","slug":"failed-to-serialize-pack-envelope-e","errorCode":null,"errorMessage":"failed to serialize pack envelope: {e}","messagePattern":"failed to serialize pack envelope: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/pack_command.rs","lineNumber":187,"sourceCode":"        let label = label_for(&targets);\n        reporter.spin(\"Packaging\", &label);\n\n        let envelope = PackEnvelope {\n            program,\n            mode: mode.clone(),\n            targets: targets\n                .iter()\n                .map(|t| baml_exec::TargetEntry {\n                    qualified_name: t.qualified_name.clone(),\n                    display_name: t.display_name.clone(),\n                    subcommand_name: t.subcommand_name.clone(),\n                })\n                .collect(),\n            output_format: self.output_format,\n        };\n        let serialized =\n            baml_artifact::encode(baml_artifact::ArtifactKind::PackedProgram, &envelope)\n                .map_err(|e| anyhow!(\"failed to serialize pack envelope: {e}\"))?;\n\n        let target_triple = self.resolved_target_triple()?;\n        let host_bytes = read_host_binary(target_triple, reporter)?;\n        let basename = self.resolve_output_basename()?;\n        let output_path = self\n            .output\n            .clone()\n            .unwrap_or_else(|| default_output_path(&basename, target_triple));\n\n        let mut output_file = std::fs::File::create(&output_path)\n            .with_context(|| format!(\"failed to create {}\", output_path.display()))?;\n        write_executable(&host_bytes, &serialized, &mut output_file, target_triple)?;\n\n        #[cfg(unix)]\n        {\n            use std::os::unix::fs::PermissionsExt;\n            std::fs::set_permissions(&output_path, std::fs::Permissions::from_mode(0o755))\n                .with_context(|| {","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/pack_command.rs#L169-L205","documentation":"After building the pack envelope (the packed program artifact), run_with_reporter serializes it via baml_artifact::encode with ArtifactKind::PackedProgram. If encoding fails, the command bails with this message carrying the underlying serialization error.","triggerScenarios":"`baml pack` reaches the envelope-encoding step and baml_artifact::encode returns an error (envelope content not serializable into the packed-program artifact format).","commonSituations":"Usually an internal issue: an envelope field that violates the artifact schema, or a format/encoding bug after a BAML version change.","solutions":["Inspect the embedded `{e}` message for the exact serialization failure.","Retry with a different `--output-format` if you passed a non-default one.","Update the BAML toolchain (`baml toolchain update`) in case this is a known encoder bug.","If it persists, reduce the packed program to a minimal case and file a BAML issue with the error text."],"exampleFix":"// before\nbaml pack myFn --output-format weird   // hypothetical bad format\n// after\nbaml toolchain update && baml pack myFn","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// treat as toolchain bug: capture stderr and retry after update\nif (stderr.includes(\"failed to serialize pack envelope\")) {\n  await run(\"baml\", [\"toolchain\", \"update\"]);\n  return run(\"baml\", [\"pack\", target]);\n}","preventionTips":["Keep the toolchain up to date","Avoid non-default --output-format unless needed","Report persistent encoder failures upstream with the embedded error text"],"tags":["cli","serialization","pack","artifact-encoding"],"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"}