Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

T09 Deny panic classes

Question

The standard denies, individually, the classes of runtime bug ADR 6/7/8 remove at compile time: unwrap_used, expect_used, panic, todo, unimplemented, exit, dbg_macro. Cerebro’s AGENTS.md already says “no unwrap in production” but enforces it by hand-grep in the pre-PR checklist, not mechanically (~460 raw matches, fewer in real production code).

Approach per crate (core → mcp → tui → cerebro):

  • clippy.toml (T02) already permits these in #[cfg(test)].
  • Convert production aborts to Result/eyre propagation.
  • main returns ExitCode instead of exit (ADR 6).
  • print_stdout/print_stderr denied workspace-wide; the binary crates (cerebro, cerebro-mcp, cerebro-tui) carry a crate-level allow for the output they legitimately produce (the library cannot talk to the world, only the binary can, ADR 8).

Exit predicate

cargo clippy --workspace green with the panic classes denied in [workspace .lints.clippy]; production code has no unwrap()/expect()/panic!()/exit() outside tests and the binary-crate print allows. The AGENTS.md grep step becomes redundant (T17 removes it).

Resolution

Done 2026-10-31. The panic classes are denied workspace-wide in [workspace.lints.clippy]: unwrap_used, expect_used, panic, todo, unimplemented, exit, dbg_macro, print_stdout, print_stderr.

The “~460 backlog” estimate was wrong and the map/fog correction matters: a grep of the raw text counts test code that clippy.toml exempts and unwrap_or-shaped calls that no lint fires on. What production actually held:

  • generators/dashboard.rs: 8 writeln!(card, ...).unwrap() on an infallible String target → let _ = (the Result can never be Err).
  • generators/journal.rs: one activity.get(date).unwrap() where dates came from activity.keys(); restructured to iterate entries, making the total absence of the panic structural rather than asserted.
  • cerebro (the command-line binary): 27 print sites → one crate-root #![allow(print_stdout, print_stderr, reason = "ADR 8")] in main.rs. A [lints.clippy] per-crate override is impossible with workspace = true (cargo rejects the merge), discovered the hard way when a manifest error masqueraded as a zero-findings clippy sweep, which is precisely why this ticket’s evidence runs just quality and not piped jq-summary one-liners alone.
  • test code that legitimately prints: two #[cfg(test)] modules (collectors smoke test, TUI journal smoke test) carry a scoped #[allow(print_stderr, reason=…)]; tests/cucumber.rs extends its file allow to unwrap_used/expect_used/panic (BDD steps lack #[test] attributes, so clippy’s test exemptions cannot reach them); tests/integration.rs gets a function-scoped allow on its git() helper.
  • exit, todo!, unimplemented!, dbg!: zero findings; the habit was already gone before the deny made it mandatory.

Gate evidence: cargo clippy --workspace --all-targets clean with the panics denied; just quality green (fmt, clippy, workspace tests, doctests, release suite, vale 0/0); cucumber 76 scenarios / 409 steps pass; cerebro status runs. The AGENTS.md hand-grep pre-PR step is now mechanically redundant; T17 removes it.