{"record":{"id":"c270254e26252d26","repo":"BoundaryML/baml","slug":"failed-to-initialize-engine-for-resolution-e","errorCode":null,"errorMessage":"failed to initialize engine for resolution: {e:?}","messagePattern":"failed to initialize engine for resolution: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/pack_command.rs","lineNumber":163,"sourceCode":"\n        let (db, program, needs_format_hint) = self.load_and_compile(reporter)?;\n        let _ = db;\n        // Mirror `baml run`'s format advisory: if any source file\n        // round-trips through `baml fmt` differently, surface a\n        // non-fatal warning so users learn to keep packaged\n        // projects formatted. Pack is a release-shaped operation,\n        // so a clean tree matters at least as much as for run.\n        if needs_format_hint {\n            reporter.warning(crate::run_command::FORMAT_HINT);\n        }\n\n        // Signature info for target resolution / reserved `help` check.\n        let engine = BexEngine::new(\n            program.clone(),\n            Arc::new(sys_native::SysOps::native()),\n            vec![],\n        )\n        .map_err(|e| anyhow!(\"failed to initialize engine for resolution: {e:?}\"))?;\n\n        let (mode, targets) = self.resolve_targets(&engine)?;\n        for t in &targets {\n            validate_help_param(&engine, &t.qualified_name)?;\n        }\n        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                })","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/pack_command.rs#L145-L181","documentation":"`baml pack` builds a BexEngine to resolve targets (and check reserved `help` params) before packaging. If BexEngine::new fails — e.g. the program cannot be loaded/resolved — run_with_reporter maps the error into this bail with the debug representation of the underlying error.","triggerScenarios":"Run `baml pack` against a program whose engine initialization fails: missing/invalid baml source, unresolved program name, or other BexEngine::new errors.","commonSituations":"Packing in a directory without a valid BAML project, pointing `--project`/`--file` at broken sources, or referencing a program name that doesn't resolve.","solutions":["Read the embedded `{e:?}` details to identify the underlying engine failure.","Verify the BAML project compiles first: run `baml check` (or `baml generate`) in the same directory and fix reported errors.","Confirm the `--project`/`--file` flags point at a valid BAML source and the program name is correct.","Retry `baml pack` after the sources resolve cleanly."],"exampleFix":"// before\nbaml pack myFunction            // broken sources -> engine init fails\n// after\nbaml check                      // fix any reported errors first\nbaml pack myFunction","handlingStrategy":"try-catch","validationCode":"# run a check before packing\nbaml check || { echo \"fix BAML errors before pack\"; exit 1; }\nbaml pack myFn","typeGuard":null,"tryCatchPattern":"// Rust caller embedding the CLI\nmatch output {\n    Ok(o) if o.status.success() => {},\n    Ok(o) if String::from_utf8_lossy(&o.stderr).contains(\"failed to initialize engine\") => {\n        eprintln!(\"engine init failed; run `baml check` for details\");\n    }\n    _ => {}\n}","preventionTips":["Always `baml check` before `baml pack`","Verify --project/--file point at valid BAML sources","Confirm program/target names resolve"],"tags":["cli","engine-init","pack","resolution"],"backgroundTag":"module-init-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"}