BoundaryML/baml · error

compilation failed

Error message

compilation failed: {e:?}

What it means

`generate_project_bytecode` failed while compiling the project to bytecode for the Bex engine; the error is wrapped with a debug-formatted cause. This means the project passed loading but could not be emitted to executable bytecode.

Solutions

  1. Inspect the debug-formatted cause `{e:?}` for the concrete emit error
  2. Simplify or fix the offending `.baml` constructs flagged in the cause
  3. Update the BAML CLI/compiler to the latest version
  4. File an issue if the construct should compile

Example fix

// before
baml run --expr 'invalid construct'
// after
# fix the .baml source / expression, then retry
baml run --expr 'MyFunction("input")'
Defensive patterns

Strategy: try-catch

Validate before calling

const diags = await baml.check(dir);
if (diags.some(d => d.severity === 'error')) throw new Error('fix diagnostics before compiling');

Try / catch

try { const engine = await runner.loadAndCompileStandalone(); } catch (e) { if (String(e).startsWith('compilation failed:')) { console.error(e.message); process.exit(1); } throw e; }

Prevention

When it happens

Trigger: `compile_to_engine` calls `baml_compiler2_emit::generate_project_bytecode(db, package)` and it returns an Err — e.g. unsupported language features or internal emit failures — when invoked from `load_and_compile_standalone` or `run_expression`.

Common situations: Compiler bugs or unhandled constructs in `.baml` sources; projects that pass diagnostics but fail a later emit phase; version skew between CLI and compiler crates.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/1ef50c989a96263a. Report an issue: GitHub.

Appendix: source

Thrown at baml_language/crates/baml_cli/src/run_command.rs:359

            .collect();
        if errors.is_empty() {
            return Ok(());
        }
        let rendered = crate::check_command::render_project_diagnostics(db, &errors);
        reporter.abandon();
        eprintln!("{rendered}");
        anyhow::bail!("{bail_context}");
    }

    /// Compile `db` to bytecode and build a `BexEngine`.
    fn compile_to_engine(
        &self,
        db: &ProjectDatabase,
        package: SourceRoot,
        argv: Vec<String>,
    ) -> Result<BexEngine> {
        let bytecode = baml_compiler2_emit::generate_project_bytecode(db, package)
            .map_err(|e| anyhow!("compilation failed: {e:?}"))?;
        BexEngine::new_with_runtime_compiler(
            bytecode,
            Arc::new(sys_native::SysOps::native()),
            argv,
            bex_project::runtime_compiler(),
        )
        .map_err(|e| anyhow!("failed to create engine: {e:?}"))
    }

    pub fn run(&self) -> Result<crate::ExitCode> {
        let reporter = Reporter::new();
        let outcome = self.run_with_reporter(&reporter);
        emit_profiling_status();
        outcome
    }
}

/// A profiling failure never breaks the run, so by default it is invisible;

View on GitHub (pinned to bd85ce9dee)