BoundaryML/baml · error · RuntimeError
error while invoking baml-cli
Error message
error while invoking baml-cli
What it means
Raised by the Ruby FFI's invoke_runtime_cli when the embedded baml-cli runtime returns an error. The original anyhow error context is formatted with {:?} into a Ruby RuntimeError. It means a baml-cli invocation (e.g. generate) run from inside the Ruby extension failed, with the CLI's own error chain embedded in the message.
Source
Thrown at engine/language_client_ruby/ext/ruby_ffi/src/lib.rs:312
ruby_to_json::RubyToJson::serialize_baml(ruby, types, partial_types, allow_partials, parsed)
.map_err(|e| {
magnus::Error::new(
ruby.exception_type_error(),
format!("failed coercing BAML value to Ruby value: {e:?}"),
)
})
}
}
fn invoke_runtime_cli(ruby: &Ruby, argv0: String, argv: Vec<String>) -> Result<u32> {
match baml_cli::run_cli(
std::iter::once(argv0).chain(argv).collect(),
baml_runtime::RuntimeCliDefaults {
output_type: baml_types::GeneratorOutputType::RubySorbet,
},
) {
Ok(exit_code) => Ok(exit_code.into()),
Err(e) => Err(Error::new(
ruby.exception_runtime_error(),
format!(
"{:?}",
e.context("error while invoking baml-cli".to_string())
),
)),
}
}
#[magnus::init(name = "ruby_ffi")]
fn init(ruby: &Ruby) -> Result<()> {
baml_log::init().map_err(|e| {
Error::new(
ruby.exception_runtime_error(),
format!("Failed to initialize BAML logger: {e:#}"),
)
})?;
View on GitHub (pinned to bd85ce9dee)
Solutions
- Read the {:?}-formatted error chain after 'error while invoking baml-cli' — it names the underlying CLI failure (file, line, reason).
- Run `baml-cli generate` manually in the same directory to see the full interactive error output.
- Fix syntax/schema errors in the .baml files reported by the CLI.
- Verify the baml_src directory exists and is reachable from the process working directory (use Dir.pwd / absolute paths).
- Check that CLI arguments passed to the FFI call are valid (no stray flags or bad paths).
Example fix
// before
result = Baml::Ffi.invoke_runtime_cli("generate", argv)
// after
begin
result = Baml::Ffi.invoke_runtime_cli("generate", argv)
rescue RuntimeError => e
warn "baml-cli failed: #{e.message}"
raise unless e.message.include?("no baml files")
end Defensive patterns
Strategy: try-catch
Validate before calling
raise 'baml_src not found' unless Dir.exist?('baml_src')
system('baml-cli', 'generate', out: File::NULL) or raise 'baml-cli not runnable in this env' Try / catch
begin
code = Baml::Ffi.invoke_runtime_cli('generate', argv)
rescue RuntimeError => e
warn "baml-cli failed: #{e.message}"
raise unless e.message.include?('No such file')
end Prevention
- Run baml-cli generate manually once in CI to surface CLI errors early.
- Use absolute paths for the baml_src directory.
- Validate .baml files (baml-cli lint if available) before invoking via FFI.
- Pin the baml CLI version to match the Ruby gem.
When it happens
Trigger: Invoking baml-cli through the Ruby FFI (invoke_runtime_cli) when the runtime command fails: missing/invalid baml_source directory, syntax errors in .baml files, unreadable working directory, or invalid CLI arguments passed through argv.
Common situations: Running `Baml::Ffi.compile` or codegen from a Rails initializer where the baml_src path is wrong; .baml files with schema errors; running the CLI with defaults that expect Ruby Sorbet output in a project not set up for it.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- compilation failed: {e:?}
- failed to generate Go SDK: {error}
- compilation failed: {e:?}
- no `.baml` files found in {}
- could not find packaged playground assets. For local debuggi
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/01ea9fa74c3922dd.
Report an issue: GitHub.