BoundaryML/baml · error
Package.current call site names a loaded package
Error message
Package.current call site names a loaded package
What it means
`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.
Source
Thrown at baml_language/crates/bex_vm/src/package_reflect/reflect.rs:65
VmRustFnError::thrown_fresh(super::type_kinds::alloc_compilation_error(
vm,
&[diagnostic],
))
}
/// Element tag for the `Arg[]` / `map<string, Arg>` containers. The class
/// instances themselves are built through the generated `copy::` structs.
const ARG_FQN: &str = "reflect.Arg";
/// Materialize the public wrapper for the package selected by the lexical
/// `Package.current()` instruction. Dynamic code uses its owning package;
/// static code uses the package name baked at the call site.
pub(crate) fn current_package_value(vm: &mut BexVm, static_package: &str) -> Value {
let runtime = vm.current_runtime_package();
let package = if runtime.is_null() {
vm.packages
.package_ptr(&baml_type::Name::new(static_package))
.expect("Package.current call site names a loaded package")
} else {
runtime
};
copy::Package {
_inner: Value::object(package),
}
.to_value(vm)
}
impl BamlPackageReflect for PackageReflectImpl {
fn _render_cause(vm: &mut BexVm, value: &Value) -> NativeCallResult {
crate::package_baml::root::render_to_string_honoring_overrides(vm, *value)
}
fn signature(vm: &mut BexVm, f: &Value) -> Result<Value, VmRustFnError> {
signature_impl(vm, *f)
}
View on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before: evaluating without loading the named package
vm.eval(entry_point);
// after
vm.load_package("my_pkg")?; // the name baked at the Package.current call site
vm.eval(entry_point); Defensive patterns
Strategy: validation
Validate before calling
// caller-side check before evaluating code that uses Package.current
if vm.packages.package_ptr(&baml_type::Name::new("my_pkg")).is_none() {
vm.load_package("my_pkg")?; // ensure the call-site package is loaded
} Try / catch
// around VM evaluation
let out = std::panic::catch_unwind(AssertUnwindSafe(|| vm.eval(entry)));
if out.is_err() { eprintln!("Package.current named an unloaded package — check loaded packages vs compiled artifacts"); } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Package.classes only contains class pointers
- Package.enums only contains enum pointers
- no-color diagnostics do not invoke the message highlighter
- rendering without a message highlighter cannot fail semantic
- diagnostic message style code is a valid Unicode variation s
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/f358e5a41c0cc4db.
Report an issue: GitHub.