BoundaryML/baml · error

StackFrame: expected Instance

Error message

StackFrame: expected Instance

What it means

Panic while converting captured stack frames to string form (error rendering / stack traces): a frame in the frames list is not an Instance. Stack traces are built from StackFrame instances; a non-Instance frame means the frames list was corrupted or built incorrectly.

Solutions

  1. Ensure error objects' frames arrays contain genuine StackFrame instances.
  2. Re-raise the error to regenerate a fresh stack trace.
  3. Report to maintainers if standard error rendering triggers this.
Defensive patterns

Strategy: validation

Validate before calling

// if constructing errors manually, ensure frames are StackFrame instances
frames.forEach(f => { if (!isInstance(f)) throw new Error('frames must be StackFrame instances'); });

Type guard

function isStackFrame(f) { return f != null && f.className === 'StackFrame'; }

Try / catch

try { renderTrace(err) } catch (e) { // fall back to printing message only
  console.error(err.message); }

Prevention

When it happens

Trigger: Formatting an error/stack trace where the stored frames array contains a value that is not a StackFrame Instance — e.g. a hand-modified frames list or a VM bug in frame capture.

Common situations: Printing errors with custom or manipulated stack traces; VM bugs in frame capture; constructing BAML error objects manually with wrong-shaped frames.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/210fea38bc7fa420. Report an issue: GitHub.

Appendix: source

Thrown at baml_language/crates/bex_vm/src/package_baml/stack_trace.rs:16

use super::{BamlClassErrorsStackTrace, BamlNamespaceErrors, PackageBamlImpl, view};
use crate::{BexVm, errors::format_traceback};

impl BamlNamespaceErrors for PackageBamlImpl {}

impl BamlClassErrorsStackTrace for PackageBamlImpl {
    #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
    fn _to_string_impl(vm: &BexVm, stacktrace: &view::errors::StackTrace<'_>) -> bex_str::BexStr {
        let frames = stacktrace.frames(vm);

        let frame_views: Vec<_> = frames
            .iter()
            .map(|frame_value| {
                let frame_instance = vm
                    .as_instance(frame_value)
                    .expect("StackFrame: expected Instance");
                view::errors::StackFrame {
                    instance: frame_instance,
                }
            })
            .collect();

        let out = format_traceback(frame_views.iter().map(|frame| {
            (
                frame.file(vm),
                frame.line() as usize,
                frame.function_name(vm),
            )
        }));

        bex_str::BexStr::from(out.trim_end().to_string())
    }
}

View on GitHub (pinned to bd85ce9dee)