Skip to content

refactor(capture): retire .expect() sites and drop quarantines#1894

Draft
goxberry wants to merge 1 commit into
goxberry/expect-cleanup-payload-remainingfrom
goxberry/expect-cleanup-lading-capture
Draft

refactor(capture): retire .expect() sites and drop quarantines#1894
goxberry wants to merge 1 commit into
goxberry/expect-cleanup-payload-remainingfrom
goxberry/expect-cleanup-lading-capture

Conversation

@goxberry
Copy link
Copy Markdown
Contributor

@goxberry goxberry commented May 22, 2026

What does this PR do?

Closes out the lading_capture .expect() cleanup. Both crate-root #![allow(clippy::expect_used)] quarantines are removed:

  • lading_capture/src/lib.rs
  • lading_capture/src/bin/fuzz_capture_harness.rs

11 production .expect() sites are addressed across the crate. Treatment mix mirrors the patterns from #1884/#1890/#1891/#1893: fn-level #[expect] for contract-style invariants where the .expect message is the contract, and site-level unreachable!() for structural infallibles.

Sites covered

7 fn-level #[expect(clippy::expect_used, reason = "...")] — the .expect() calls themselves are unchanged.

Function Sites Why the panic is intentional
test/writer.rs::InMemoryWriter::{get_bytes, get_string, parse_lines} + Write::write 4 InMemoryWriter is a test/fuzz helper (#![cfg(any(test, feature = "fuzz"))]). The mutex-poisoning and invalid-UTF-8 panics are documented contracts (see # Panics sections).
manager/state_machine.rs::StateMachine::record_captures 1 self.format.as_mut()format is Some throughout the operating state of the state machine.
manager/state_machine.rs::StateMachine::drain_and_write 1 same
manager/state_machine.rs::StateMachine::write_metric_line 3 same (3 .expect() calls collapse to one fn-level annotation)
manager.rs::CaptureManager::start 1 self.shutdown.take()shutdown is populated at construction and consumed exactly once here.

4 site-level .unwrap_or_else(... unreachable!("...")) — structural infallibles.

File:line Site Why infallible
manager.rs::RealClock::now_ms (start_system_time + elapsed).duration_since(UNIX_EPOCH) start_system_time is captured at program start in a modern epoch, well after UNIX_EPOCH.
accumulator.rs:230, 525 dogsketch.write_to_bytes() prost::Message::write_to_bytes on an in-memory struct cannot fail.
bin/fuzz_capture_harness.rs:389 op_iter.next() OpIterator::next() is structurally infinite — every match arm returns Some(...); the fallback is unreachable!().

Discovery note

The initial survey reported "149 production sites" in lading_capture. Once the quarantines were temporarily removed and cargo clippy -p lading-capture --all-targets --all-features was run, only 11 real sites surfaced. The bulk of the original 149 was inside #[cfg(test)] mod tests { ... } blocks at the bottom of .rs files — covered by allow-expect-in-tests = true once the crate-level allow is gone.

Motivation

Second-to-last sub-stack in the cleanup chain. After this, only lading (243 surveyed sites; similar pattern expected) remains to bring the whole workspace to zero expect_used violations.

Related issues

Stacked on #1893.

Additional Notes

  • cargo build --all-targets --all-features
  • bash ci/validate ✓ (full suite, including kani proofs and loom tests)
  • cargo clippy -p lading-capture --all-targets --all-features 2>&1 | grep -c expect_used0
  • Diff: 7 files, +63 −15.

Closes out the `lading_capture` `.expect()` cleanup. Both crate-root
`#![allow(clippy::expect_used)]` quarantines are removed:

- `lading_capture/src/lib.rs`
- `lading_capture/src/bin/fuzz_capture_harness.rs`

11 production `.expect()` sites are addressed across the crate. Treatment
mix mirrors the patterns established by #1884/#1890/#1891/#1893:

**fn-level `#[expect(clippy::expect_used, reason = "...")]`** (7 sites
across 7 functions; the .expect msg is the documented contract):

- `test/writer.rs` (×4) — `InMemoryWriter` test/fuzz helper, gated by
  `#![cfg(any(test, feature = "fuzz"))]`. The mutex-poisoning and
  invalid-UTF-8 panics are the type's documented contract above each fn.
- `manager/state_machine.rs::StateMachine::{record_captures,
  drain_and_write, write_metric_line}` — six `self.format.as_mut()`
  sites collapse to three fn-level annotations. `self.format` is `Some`
  throughout the operating state of the state machine.
- `manager.rs::CaptureManager::start` — `self.shutdown.take()` is
  consumed exactly once here; `self.shutdown` is populated at
  construction.

**Site-level `.unwrap_or_else(... unreachable!("..."))`** (4 sites,
structural infallibles):

- `manager.rs::RealClock::now_ms` — `SystemTime::duration_since(UNIX_EPOCH)`
  on a `start_system_time` captured at program start in a modern epoch.
- `accumulator.rs` (×2) — `prost::Message::write_to_bytes` on an
  in-memory `Dogsketch` cannot fail.
- `bin/fuzz_capture_harness.rs` — `OpIterator::next()` is structurally
  infinite (every match arm returns `Some(...)`, fallback is
  `unreachable!()`).

`lading_capture` is now fully covered by the workspace-level
`clippy::expect_used = "deny"`. No runtime behavior change. Verified
with `bash ci/validate` (full suite: shellcheck, fmt, check, custom
lints, clippy, deny, config validation, nextest, loom, kani, buf).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copy link
Copy Markdown
Contributor Author

goxberry commented May 22, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

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