{"record":{"id":"c934a41408c003d8","repo":"BoundaryML/baml","slug":"baml-panics-cancelled","errorCode":"baml.panics.Cancelled","errorMessage":"operation cancelled","messagePattern":"operation cancelled","errorType":"error_code","errorClass":"VmPanic","httpStatus":null,"severity":"warning","filePath":"baml_language/crates/bex_vm_types/src/errors.rs","lineNumber":57,"sourceCode":"    #[error(\"invalid field access: field {field_index} of {field_count}\")]\n    InvalidFieldAccess {\n        field_index: usize,\n        field_count: usize,\n    },\n\n    #[error(\"key not found in map\")]\n    MapKeyNotFound,\n\n    #[error(\"stack overflow\")]\n    StackOverflow,\n\n    #[error(\"assertion failed\")]\n    AssertionFailed,\n\n    #[error(\"unreachable code executed\")]\n    Unreachable,\n\n    #[error(\"operation cancelled\")]\n    Cancelled,\n\n    /// A user-caused panic from `baml.sys.panic`, and the stdlib's panic of\n    /// record for a user-violated native invariant (e.g. a reflection kind\n    /// view's `_ty` field overwritten with a type of a different kind).\n    #[error(\"baml.sys.panic: {message}\")]\n    UserPanic { message: String },\n\n    /// A clean process-termination request from `baml.sys.exit(code)`.\n    ///\n    /// Catchable in user code as `baml.panics.Exit` — patterned after\n    /// Python's `SystemExit`: code can intercept it for cleanup or\n    /// testing, and if nothing catches it the engine surfaces the code\n    /// as `EngineError::Exit` and the host terminates with it.\n    ///\n    /// BAML `int` is `i64`, so the signal carries the full value the\n    /// user wrote; the host narrows to `i32` for `std::process::exit`.\n    #[error(\"baml.sys.exit({code})\")]","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm_types/src/errors.rs#L39-L75","documentation":"Raised when a running BAML operation is cancelled, typically because the host or user requested termination of the execution (e.g. a cancellation token or deadline fired). It is the VM's cooperative cancellation signal for long-running work.","triggerScenarios":"The host calls the VM's cancel/abort API while execution is in progress, a timeout elapses, or a user interrupts a long-running LLM call; the next cancellation check point panics with `Cancelled`.","commonSituations":"CLI Ctrl+C during a BAML function run, request timeouts in a server wrapping the VM, test harnesses cancelling stuck executions.","solutions":["Treat it as an expected cancellation: catch `baml.panics.Cancelled` and unwind cleanly.","Check the cancellation source (timeout, user abort) and retry with a longer budget if cancellation was premature.","Make long-running BAML code hit cancellation checkpoints regularly so it stops promptly."],"exampleFix":"// host side: catch and treat as cooperative stop\nmatch vm.run(func) {\n  Err(Panic::Cancelled) => info!(\"execution cancelled by host\"),\n  other => other?,\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// BAML\ntry {\n  long_task();\n} catch (e: baml.panics.Cancelled) {\n  cleanup();\n  return err(\"cancelled\");\n}","preventionTips":["Budget timeouts generously enough for the workload","Poll cancellation-friendly primitives in long loops","Keep cancellation handling idempotent for re-entry"],"tags":["vm","cancellation","timeout","panic","baml"],"backgroundTag":"thread-interrupted","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"}