#4967·baml

[bug] `catch_all` does not catch an `assert.*` failure raised inside the called function

Author: BenSpexCreated Sep 22, 2026Updated Sep 22, 2026

Summary

A function call wrapped in catch_all (e) { ... } is expected to route any failure from the called function into the handler, and let the wrapping function return normally. When the called function fails via assert.equal/assert.not_null (rather than an explicit throws error), the failure is not routed to catch_all — it propagates straight out as a raw runtime assertion failure, and (inside a test { } block) is reported as if it were the outer test's own failed assertion, with no mention that catch_all was even present in the call chain. This makes catch_all unreliable as a general "did this call succeed" wrapper: it silently does not cover one whole class of failure that a called function can produce.

Environment

  • BAML toolchain 0.20.1 (baml.toml: [package] name = "catch-all-assert-repro", [toolchain] version = "0.20.1"; baml check passes). Also reproduces unchanged on 0.20.0.
  • No LLM call, network access, or credentials required — pure local BAML functions.
  • Linux x86_64, baml-cli invoked directly (BAML_AGENT_SKILL_CHECK=off).

Repro

baml_src/main.baml:

baml
function CheckPositive(v: int) -> string {
    assert.equal(v > 0, true);
    "ok"
}

function TryCheck(v: int) -> string {
    CheckPositive(v) catch_all (e) {
        _ => `caught: ${e}`,
    }
}

test "catch_all catches an assertion failure" {
    let result = TryCheck(-1);
    assert.equal(result, "caught: assertion failed")
}

Run: BAML_AGENT_SKILL_CHECK=off baml-cli test (from this directory, with the 0.20.1 toolchain on PATH, or ~/.baml/toolchains/0.20.1/bin/baml-cli test).

Output

FAIL root::catch_all catches an assertion failure (0ms)
AGGREGATE FAIL [outcome=fail]
  => assertion failed: left = false, right = true
error: test failures — 0 passed, 1 failed, 1 total

The failure message (left = false, right = true) is CheckPositive's own assert.equal(v > 0, true) — it never reaches TryCheck's catch_all (e) { ... } handler. The outer test's own assert.equal(result, "caught: assertion failed") never runs; there is no way to tell from the output that a catch_all was in the call path at all.

Expected

Either:

  1. catch_all catches an assert.* failure from the called function the same way it catches a throws-declared error (the handler runs, e carries the assertion's message, and the wrapping function returns the handler's value), or
  2. if this is intentional — assert.* is meant to be an unconditionally-fatal test primitive, never a catchable runtime error — the documentation for catch_all should say so explicitly, since nothing in its own signature or examples suggests one class of "the called function didn't return successfully" is exempt.

Why this matters

A common pattern for testing "does my function correctly reject bad input" is to wrap the call in catch_all and assert the caught error's shape, rather than asserting the raw failure text (which may be internal/opaque). Today that pattern silently doesn't work when the underlying rejection mechanism is assert.* (as opposed to an explicit throw), and the surrounding test fails with a confusing, unrelated-looking assertion-failure message instead of exercising the intended catch-and-inspect path.