{"record":{"id":"b9b2961a3f660bb3","repo":"BoundaryML/baml","slug":"baml-sys-exit-code","errorCode":null,"errorMessage":"baml.sys.exit({code})","messagePattern":"baml\\.sys\\.exit\\((.+?)\\)","errorType":"exception","errorClass":"EngineError","httpStatus":null,"severity":"info","filePath":"baml_language/crates/bex_engine/src/lib.rs","lineNumber":839,"sourceCode":"\n    #[error(\"{}\", format_vm_internal_error(source, trace))]\n    TracedVmInternalError {\n        source: bex_vm::errors::VmInternalError,\n        trace: Vec<bex_vm::StackFrame>,\n    },\n\n    /// Either a BAML panic or a BAML error value.\n    #[error(\"{}\", format_unhandled_throw(value, trace))]\n    UnhandledThrow {\n        value: Box<BexExternalValue>,\n        trace: Vec<bex_vm::StackFrame>,\n    },\n\n    /// Clean process-termination request from `baml.sys.exit(code)`.\n    /// The caller is expected to honor this as the process exit code.\n    /// BAML `int` is `i64`, so the signal carries the full value; the\n    /// caller clamps into its shell's range (typically 0..=255 on Unix).\n    #[error(\"baml.sys.exit({code})\")]\n    Exit { code: i64 },\n\n    #[error(\"Cannot convert object of type {type_name}\")]\n    CannotConvert { type_name: String },\n\n    #[error(\"Type mismatch: {message}\")]\n    TypeMismatch { message: String },\n\n    #[error(\"Schema inconsistency: {message}\")]\n    SchemaInconsistency { message: String },\n\n    #[cfg(feature = \"heap_debug\")]\n    #[error(\"Snapshot not possible for type: {type_name}\")]\n    CannotSnapshot { type_name: String },\n\n    #[error(\"A function call with ID {call_id} is already in progress\")]\n    DuplicateCallId { call_id: CallId },\n","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_engine/src/lib.rs#L821-L857","documentation":"Not a failure: a structured signal raised when BAML code calls `baml.sys.exit(code)`, requesting clean process termination. The error variant carries the full i64 exit code; the embedding caller is expected to honor it as the process exit status, clamping to the shell's range (typically 0..=255 on Unix).","triggerScenarios":"A BAML function calls `baml.sys.exit(code)` and the engine surfaces it as this variant instead of terminating the host process directly.","commonSituations":"CLI-style BAML scripts that want to set their Unix exit status; tests that trigger early-exit paths; embedding the engine in a server where exit must be intercepted.","solutions":["Catch/handle this variant in the host and exit the process with the given code (clamped to 0..=255)","If exit is unexpected, audit the BAML code for baml.sys.exit calls","In server embeddings, translate it into a request-scoped abort rather than killing the process"],"exampleFix":"// host code (rust, conceptual)\n// before: treats it as generic failure\nErr(e) => panic!(\"{}\", e),\n// after\nErr(EngineError::Exit { code }) => std::process::exit(code.clamp(0, 255) as i32),","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(EngineError::Exit { code }) => std::process::exit(code.clamp(0, 255) as i32),\n    Ok(v) => use(v),\n    Err(e) => handle(e),\n}","preventionTips":["Treat Exit as control flow, not failure, in host glue","Audit BAML scripts for baml.sys.exit before embedding in servers","Clamp the i64 code to the OS exit-status range"],"tags":["exit","process","sysop"],"backgroundTag":"process-exit-request","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"}