{"record":{"id":"f358e5a41c0cc4db","repo":"BoundaryML/baml","slug":"package-current-call-site-names-a-loaded-package","errorCode":null,"errorMessage":"Package.current call site names a loaded package","messagePattern":"Package\\.current call site names a loaded package","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_reflect/reflect.rs","lineNumber":65,"sourceCode":"    VmRustFnError::thrown_fresh(super::type_kinds::alloc_compilation_error(\n        vm,\n        &[diagnostic],\n    ))\n}\n\n/// Element tag for the `Arg[]` / `map<string, Arg>` containers. The class\n/// instances themselves are built through the generated `copy::` structs.\nconst ARG_FQN: &str = \"reflect.Arg\";\n\n/// Materialize the public wrapper for the package selected by the lexical\n/// `Package.current()` instruction. Dynamic code uses its owning package;\n/// static code uses the package name baked at the call site.\npub(crate) fn current_package_value(vm: &mut BexVm, static_package: &str) -> Value {\n    let runtime = vm.current_runtime_package();\n    let package = if runtime.is_null() {\n        vm.packages\n            .package_ptr(&baml_type::Name::new(static_package))\n            .expect(\"Package.current call site names a loaded package\")\n    } else {\n        runtime\n    };\n    copy::Package {\n        _inner: Value::object(package),\n    }\n    .to_value(vm)\n}\n\nimpl BamlPackageReflect for PackageReflectImpl {\n    fn _render_cause(vm: &mut BexVm, value: &Value) -> NativeCallResult {\n        crate::package_baml::root::render_to_string_honoring_overrides(vm, *value)\n    }\n\n    fn signature(vm: &mut BexVm, f: &Value) -> Result<Value, VmRustFnError> {\n        signature_impl(vm, *f)\n    }\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_reflect/reflect.rs#L47-L83","documentation":"`current_package_value` resolves the package for a `Package.current` call: it uses the runtime package when one is active, otherwise it looks up the package named at the call site. The panic means the static package name baked into the call site does not correspond to any package loaded into the VM — a compile/runtime agreement invariant.","triggerScenarios":"Evaluating a `Package.current` expression in a context with no active runtime package while `vm.packages.package_ptr(name)` returns None — e.g. the named package was never registered, was unloaded, or the call site's baked name doesn't match a loaded package (renamed or stale artifacts).","commonSituations":"Running compiled BAML modules against a VM that loaded a different/renamed set of packages; stale compiled artifacts after a package rename; evaluating snippets in a bare VM without loading the referenced package first.","solutions":["Load the package named at the call site into the VM before evaluating code that uses Package.current.","Recompile/rebuild the modules so the baked package name matches the currently loaded package set.","Ensure the code runs within a runtime package context (package entry point) rather than bare evaluation.","Check for package name mismatches (typos, renames) between the compile-time manifest and the VM's loaded packages."],"exampleFix":"// before: evaluating without loading the named package\nvm.eval(entry_point);\n// after\nvm.load_package(\"my_pkg\")?; // the name baked at the Package.current call site\nvm.eval(entry_point);","handlingStrategy":"validation","validationCode":"// caller-side check before evaluating code that uses Package.current\nif vm.packages.package_ptr(&baml_type::Name::new(\"my_pkg\")).is_none() {\n    vm.load_package(\"my_pkg\")?; // ensure the call-site package is loaded\n}","typeGuard":null,"tryCatchPattern":"// around VM evaluation\nlet out = std::panic::catch_unwind(AssertUnwindSafe(|| vm.eval(entry)));\nif out.is_err() { eprintln!(\"Package.current named an unloaded package — check loaded packages vs compiled artifacts\"); }","preventionTips":["Always load every package a module references before evaluating it.","Recompile modules after renaming packages so baked call-site names stay in sync.","Run Package.current-dependent code inside a runtime package context when possible.","Add a startup check comparing compiled manifests against vm.packages contents."],"tags":["rust","vm","packages","invariant"],"backgroundTag":"resource-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}