{"record":{"id":"210fea38bc7fa420","repo":"BoundaryML/baml","slug":"stackframe-expected-instance","errorCode":null,"errorMessage":"StackFrame: expected Instance","messagePattern":"StackFrame: expected Instance","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/stack_trace.rs","lineNumber":16,"sourceCode":"use super::{BamlClassErrorsStackTrace, BamlNamespaceErrors, PackageBamlImpl, view};\nuse crate::{BexVm, errors::format_traceback};\n\nimpl BamlNamespaceErrors for PackageBamlImpl {}\n\nimpl BamlClassErrorsStackTrace for PackageBamlImpl {\n    #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]\n    fn _to_string_impl(vm: &BexVm, stacktrace: &view::errors::StackTrace<'_>) -> bex_str::BexStr {\n        let frames = stacktrace.frames(vm);\n\n        let frame_views: Vec<_> = frames\n            .iter()\n            .map(|frame_value| {\n                let frame_instance = vm\n                    .as_instance(frame_value)\n                    .expect(\"StackFrame: expected Instance\");\n                view::errors::StackFrame {\n                    instance: frame_instance,\n                }\n            })\n            .collect();\n\n        let out = format_traceback(frame_views.iter().map(|frame| {\n            (\n                frame.file(vm),\n                frame.line() as usize,\n                frame.function_name(vm),\n            )\n        }));\n\n        bex_str::BexStr::from(out.trim_end().to_string())\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/stack_trace.rs#L1-L34","documentation":"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.","triggerScenarios":"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.","commonSituations":"Printing errors with custom or manipulated stack traces; VM bugs in frame capture; constructing BAML error objects manually with wrong-shaped frames.","solutions":["Ensure error objects' frames arrays contain genuine StackFrame instances.","Re-raise the error to regenerate a fresh stack trace.","Report to maintainers if standard error rendering triggers this."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// if constructing errors manually, ensure frames are StackFrame instances\nframes.forEach(f => { if (!isInstance(f)) throw new Error('frames must be StackFrame instances'); });","typeGuard":"function isStackFrame(f) { return f != null && f.className === 'StackFrame'; }","tryCatchPattern":"try { renderTrace(err) } catch (e) { // fall back to printing message only\n  console.error(err.message); }","preventionTips":["Do not hand-edit error frame lists.","Re-raise errors instead of rebuilding trace objects."],"tags":["vm-panic","invariant","stack-trace","error-handling"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}