Skip to content

[codex] Report missing catch_all throw arms#3723

Open
aaronvg wants to merge 2 commits into
canaryfrom
codex/catch-all-missing-throw-diagnostic
Open

[codex] Report missing catch_all throw arms#3723
aaronvg wants to merge 2 commits into
canaryfrom
codex/catch-all-missing-throw-diagnostic

Conversation

@aaronvg

@aaronvg aaronvg commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Report a non-exhaustive catch_all diagnostic when typed catch arms leave inferred throw types unhandled.
  • Add a regression covering a call graph that throws both BuildError and string, where only BuildError is caught.
  • Keep the diagnostic on the existing non-exhaustive match code path (E0062) while rendering catch-specific wording.

Root Cause

catch_all cleared the residual throw set after checking its arms, so unhandled non-panic throw facts were treated as fully handled and no diagnostic escaped.

Validation

  • cargo nextest run -p baml_tests diagnostic_errors::catch_throw_regressions
  • git diff --check

Note

Low Risk
Type-checker-only change to catch exhaustiveness; no runtime or auth paths, with behavior covered by diagnostic tests.

Overview
catch_all handlers that leave inferred throw types unhandled now emit a compile error instead of silently clearing the residual throw set.

TIR catch inference reports TirTypeError::NonExhaustiveCatchAll when a catch_all / catch_all_panics clause still has unhandled types in residual after its arms run, listing the missing throw types against the clause binding type. LSP/check rendering uses catch-specific wording while reusing E0062 (NonExhaustiveMatch).

Tests now expect this diagnostic for partial catch_all (e.g. only string when int | string can throw) and add a regression where a call chain throws BuildError | string but only BuildError is caught.

Reviewed by Cursor Bugbot for commit f774e33. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features

    • The compiler now reports non-exhaustive catch-all error handlers with a clear diagnostic listing the caught type and which throw cases are missing.
  • Tests

    • Added/updated regression tests to verify catch-all exhaustiveness diagnostics and expected error codes.

@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jun 9, 2026 8:30pm
promptfiddle Ready Ready Preview, Comment Jun 9, 2026 8:30pm
promptfiddle2 Ready Ready Preview, Comment Jun 9, 2026 8:30pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 77d8d808-e025-48b8-aff8-8a6550cfe0ef

📥 Commits

Reviewing files that changed from the base of the PR and between 1613a18 and f774e33.

📒 Files selected for processing (1)
  • baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/catch/catch_all_exhaustive.baml

📝 Walkthrough

Walkthrough

Adds exhaustiveness checking for catch_all expressions: a new NonExhaustiveCatchAll error records the caught type and missing cases, the compiler emits this diagnostic when a catch_all doesn't cover all inferred throw types, LSP formatting and diagnostic IDs are updated, and tests/expectations adjusted.

Changes

Catch-All Exhaustiveness Checking

Layer / File(s) Summary
Error type definition and display
baml_language/crates/baml_compiler2_tir/src/infer_context.rs
Introduces TirTypeError::NonExhaustiveCatchAll { caught_type: Ty, missing_cases: Vec<String> } and adds a fmt::Display arm to render a non-exhaustive catch_all message.
Diagnostic emission in catch expression inference
baml_language/crates/baml_compiler2_tir/src/builder.rs
In infer_catch_expr, when processing CatchAll/CatchAllPanics and the residual throw set is non-empty, emits NonExhaustiveCatchAll with the clause binding type and renderable missing cases, then clears the residual.
LSP diagnostic formatting and classification
baml_language/crates/baml_lsp2_actions/src/check.rs
Adds source-aware rendering for NonExhaustiveCatchAll messages and maps the variant to DiagnosticId::NonExhaustiveMatch so it shares the existing diagnostic classification.
Regression tests and test expectations
baml_language/crates/baml_tests/projects/diagnostic_errors/catch_throw_regressions/regressions.baml, baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/catch/catch_all_exhaustive.baml
Adds BuildError, generators that may throw different types, a catch_all recovery example exercising partial coverage, and updates expected diagnostics to assert the new non-exhaustive catch_all diagnostic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • BoundaryML/baml#3417: Refactors catch-pattern and throw-set matching plumbing in infer_catch_expr, which this PR builds upon to add exhaustiveness diagnostics.

Poem

🐰 I hopped through throws both big and small,

Found a catch_all that missed one call,
Now errors list the types left out,
So matches leave no room for doubt,
A tidy hop — no crumbs to fall.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title '[codex] Report missing catch_all throw arms' directly matches the core change: adding diagnostics for non-exhaustive catch_all when throw types are unhandled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/catch-all-missing-throw-diagnostic

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@aaronvg aaronvg marked this pull request as ready for review June 9, 2026 19:48
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

No description provided.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
baml_language/crates/baml_compiler2_tir/src/builder.rs (1)

6580-6592: Testing guideline: baml_compiler2_tir unit coverage appears to be exercised via CI
The repo’s CI workflow .github/workflows/cargo-tests.reusable.yaml runs cargo nextest run --all-features for the baml_language workspace excluding only baml_tests and sdk_test_*, which should include baml_compiler2_tir unit tests. There’s no explicit cargo test --lib -p baml_compiler2_tir command in the workflows, so align the PR/test notes with what was actually run (or run that exact command locally per the guideline).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_compiler2_tir/src/builder.rs` around lines 6580 -
6592, Update the PR/test notes to accurately reflect how tests are executed in
CI: state that the workflow cargo-tests.reusable.yaml runs `cargo nextest run
--all-features` for the baml_language workspace (which includes the
baml_compiler2_tir crate except for the excluded baml_tests and sdk_test_*
crates), or alternatively run and report the exact local command `cargo test
--lib -p baml_compiler2_tir` if you validated tests locally; ensure the PR
description or testing section explicitly mentions which command was run and the
observed results so readers know baml_compiler2_tir was covered by CI.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/crates/baml_lsp2_actions/src/check.rs`:
- Around line 6240-6253: Run the library tests and attach their output to the
PR: from the repository root run `cargo test --lib` in the crate
baml_language/crates/baml_lsp2_actions (or `cd
baml_language/crates/baml_lsp2_actions && cargo test --lib`), capture the full
terminal output (stdout/stderr) showing all tests (116/116) passing, and add
that output to the PR either as a pasted comment or as an attached file (e.g.,
test-output.txt). Confirm the command ran successfully and include the exact
captured output in the PR so reviewers can verify the library tests passed.

---

Nitpick comments:
In `@baml_language/crates/baml_compiler2_tir/src/builder.rs`:
- Around line 6580-6592: Update the PR/test notes to accurately reflect how
tests are executed in CI: state that the workflow cargo-tests.reusable.yaml runs
`cargo nextest run --all-features` for the baml_language workspace (which
includes the baml_compiler2_tir crate except for the excluded baml_tests and
sdk_test_* crates), or alternatively run and report the exact local command
`cargo test --lib -p baml_compiler2_tir` if you validated tests locally; ensure
the PR description or testing section explicitly mentions which command was run
and the observed results so readers know baml_compiler2_tir was covered by CI.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6135c818-9c6a-4f27-b5d5-a915e2afea09

📥 Commits

Reviewing files that changed from the base of the PR and between 78f9131 and 1613a18.

⛔ Files ignored due to path filters (6)
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__01_lexer__regressions.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__02_parser__regressions.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__03_hir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__04_tir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__05_diagnostics.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__10_formatter__regressions.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • baml_language/crates/baml_compiler2_tir/src/builder.rs
  • baml_language/crates/baml_compiler2_tir/src/infer_context.rs
  • baml_language/crates/baml_lsp2_actions/src/check.rs
  • baml_language/crates/baml_tests/projects/diagnostic_errors/catch_throw_regressions/regressions.baml

Comment thread baml_language/crates/baml_lsp2_actions/src/check.rs
@aaronvg aaronvg added this pull request to the merge queue Jun 9, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant