{"record":{"id":"aded8afcdd03d06f","repo":"BoundaryML/baml","slug":"baml-panics-exit","errorCode":"baml.panics.Exit","errorMessage":"baml.sys.exit({code})","messagePattern":"baml\\.sys\\.exit\\((.+?)\\)","errorType":"error_code","errorClass":"VmPanic","httpStatus":null,"severity":"warning","filePath":"baml_language/crates/bex_vm_types/src/errors.rs","lineNumber":75,"sourceCode":"    #[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})\")]\n    Exit { code: i64 },\n\n    /// The graceful-ish way to handle potential OOM errors, instead of hard-crashing.\n    #[error(\"memory allocation failed: {message}\")]\n    AllocFailure { message: String },\n\n    /// A required host resource is unavailable — e.g. the OS entropy source\n    /// returned an error in a sandboxed runtime. Catchable so user code can\n    /// fall back gracefully instead of aborting the host process.\n    #[error(\"host resource '{resource}' unavailable: {message}\")]\n    HostUnavailable { resource: String, message: String },\n\n    /// The right operand of a bigint shift (`<<` / `>>`) was negative.\n    /// Catchable because the count is a runtime `bigint` and the type\n    /// system can't rule out negative values.\n    #[error(\"negative bit shift: {message}\")]\n    NegativeBitShift { message: String },\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm_types/src/errors.rs#L57-L93","documentation":"A clean process-termination request raised by `baml.sys.exit(code)`. It is catchable in user code as `baml.panics.Exit` — patterned after Python's `SystemExit` — so code can intercept it for cleanup or testing. If nothing catches it, the engine surfaces the code as `EngineError::Exit` and the host terminates with it; BAML's i64 int is narrowed to i32 by the host for `std::process::exit`.","triggerScenarios":"BAML code calls `baml.sys.exit(n)` with any i64 code; the panic propagates unless caught by a `baml.panics.Exit` handler, in which case execution continues after the catch site.","commonSituations":"CLI-style BAML programs exiting with a status code on validation failure, tests intercepting exit requests to assert the code, top-level scripts terminating early on missing input.","solutions":["If you did not intend termination, remove or guard the `baml.sys.exit` call.","Catch `baml.panics.Exit` to intercept the request for cleanup or testing instead of letting the process end.","Use conventional exit codes (0 success, non-zero failure) so the host's i32 narrowing produces meaningful process status."],"exampleFix":"// before\nbaml.sys.exit(1); // hard-terminates the host\n// after\ntry {\n  baml.sys.exit(1);\n} catch (e: baml.panics.Exit) {\n  log(\"cleanup before exit\");\n  rethrow;\n}","handlingStrategy":"try-catch","validationCode":"// BAML: decide explicitly whether to exit or return\nif (fatal) { return err(code); } // instead of baml.sys.exit(code) in library code","typeGuard":null,"tryCatchPattern":"// BAML\ntry {\n  main();\n} catch (e: baml.panics.Exit) {\n  cleanup();\n  rethrow; // let the host exit with e.code\n}","preventionTips":["Call baml.sys.exit only at the program's top level, never inside library functions","Use exit codes within i32 range with conventional 0/non-zero semantics","In tests, wrap calls in a catch for baml.panics.Exit to assert the code"],"tags":["vm","exit","process","panic","baml"],"backgroundTag":"invalid-state-transition","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"}