{"record":{"id":"01ea9fa74c3922dd","repo":"BoundaryML/baml","slug":"error-while-invoking-baml-cli","errorCode":null,"errorMessage":"error while invoking baml-cli","messagePattern":"error while invoking baml-cli","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/lib.rs","lineNumber":312,"sourceCode":"        ruby_to_json::RubyToJson::serialize_baml(ruby, types, partial_types, allow_partials, parsed)\n            .map_err(|e| {\n                magnus::Error::new(\n                    ruby.exception_type_error(),\n                    format!(\"failed coercing BAML value to Ruby value: {e:?}\"),\n                )\n            })\n    }\n}\n\nfn invoke_runtime_cli(ruby: &Ruby, argv0: String, argv: Vec<String>) -> Result<u32> {\n    match baml_cli::run_cli(\n        std::iter::once(argv0).chain(argv).collect(),\n        baml_runtime::RuntimeCliDefaults {\n            output_type: baml_types::GeneratorOutputType::RubySorbet,\n        },\n    ) {\n        Ok(exit_code) => Ok(exit_code.into()),\n        Err(e) => Err(Error::new(\n            ruby.exception_runtime_error(),\n            format!(\n                \"{:?}\",\n                e.context(\"error while invoking baml-cli\".to_string())\n            ),\n        )),\n    }\n}\n\n#[magnus::init(name = \"ruby_ffi\")]\nfn init(ruby: &Ruby) -> Result<()> {\n    baml_log::init().map_err(|e| {\n        Error::new(\n            ruby.exception_runtime_error(),\n            format!(\"Failed to initialize BAML logger: {e:#}\"),\n        )\n    })?;\n","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs#L294-L330","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nresult = Baml::Ffi.invoke_runtime_cli(\"generate\", argv)\n\n// after\nbegin\n  result = Baml::Ffi.invoke_runtime_cli(\"generate\", argv)\nrescue RuntimeError => e\n  warn \"baml-cli failed: #{e.message}\"\n  raise unless e.message.include?(\"no baml files\")\nend","handlingStrategy":"try-catch","validationCode":"raise 'baml_src not found' unless Dir.exist?('baml_src')\nsystem('baml-cli', 'generate', out: File::NULL) or raise 'baml-cli not runnable in this env'","typeGuard":null,"tryCatchPattern":"begin\n  code = Baml::Ffi.invoke_runtime_cli('generate', argv)\nrescue RuntimeError => e\n  warn \"baml-cli failed: #{e.message}\"\n  raise unless e.message.include?('No such file')\nend","preventionTips":["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."],"tags":["ruby","cli","codegen","baml"],"backgroundTag":"invalid-cli-argument","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"}