Skip to content

Commit 622f36e

Browse files
goxberryclaude
andcommitted
refactor(lading): annotate intentional-panic observer/target sites
Attach fn-level #[expect(clippy::expect_used, reason = "...")] to remaining production .expect() sites in the observer, target, target metrics scrapers, neper thread spawning, captool analysis, and the inspector. Tests still rely on the crate-level allow quarantine and will be retained when PR 6 drops it. - observer.rs::run (PID handshake invariant) - observer/linux/procfs.rs::{handle_process, proc_exe} - observer/linux/cgroup/v2/cpu.rs::poll (cgroup v2 kernel ABI) - observer/linux/procfs/memory/smaps.rs::into_region_strs (const regex) - target.rs::{watch_container, execute_binary} (PID type conversion) - target_metrics/expvar.rs::run (reqwest TLS bootstrap) - target_metrics/prometheus.rs::parse_prometheus_metrics (FIXME) - target_metrics/prometheus.rs::LABEL_REGEX (const regex) - inspector.rs::run (PID type conversion) - neper/thread.rs::spawn_named (OS thread alloc) - bin/captool/analyze/jsonl.rs::analyze_metric (paired-map invariant) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent d87c012 commit 622f36e

10 files changed

Lines changed: 52 additions & 0 deletions

File tree

lading/src/bin/captool/analyze/jsonl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ pub(crate) fn list_metrics(lines: &[Line]) -> Vec<MetricInfo> {
3838
/// Returns statistics grouped by label set (context).
3939
#[must_use]
4040
#[expect(clippy::cast_precision_loss)]
41+
#[expect(
42+
clippy::expect_used,
43+
reason = "context_map and fetch_indices are populated together by the same loop; a missing fetch_indices entry indicates a programming error in the caller"
44+
)]
4145
pub(crate) fn analyze_metric(
4246
lines: &[Line],
4347
metric_name: &str,

lading/src/inspector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ impl Server {
123123
/// # Panics
124124
///
125125
/// None are known.
126+
#[expect(
127+
clippy::expect_used,
128+
reason = "child.id() returning Some always fits in i32 on supported platforms; a failure here indicates a platform invariant violation"
129+
)]
126130
pub async fn run(self, mut pid_snd: TargetPidReceiver) -> Result<ExitStatus, Error> {
127131
let target_pid = pid_snd.recv().await?;
128132
drop(pid_snd);

lading/src/neper/thread.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub(crate) fn join_all<T>(handles: Vec<JoinHandle<T>>) -> Result<Vec<T>, ()> {
4545
}
4646

4747
/// Spawn a named OS thread running `f`.
48+
#[expect(
49+
clippy::expect_used,
50+
reason = "thread::Builder::spawn fails only when the OS cannot allocate a thread; this is an unrecoverable resource exhaustion"
51+
)]
4852
pub(crate) fn spawn_named<F, T>(name: &str, f: F) -> JoinHandle<T>
4953
where
5054
F: FnOnce() -> T + Send + 'static,

lading/src/observer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ impl Server {
103103
clippy::cast_possible_truncation,
104104
clippy::cast_sign_loss
105105
)]
106+
#[expect(
107+
clippy::expect_used,
108+
reason = "the observer requires the target PID to begin sampling; a missing PID at this point indicates an unrecoverable orchestration failure"
109+
)]
106110
#[cfg(target_os = "linux")]
107111
pub async fn run(
108112
self,

lading/src/observer/linux/cgroup/v2/cpu.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ impl Sampler {
4141
}
4242

4343
// Read cgroup CPU data and calculate a percentage of usage.
44+
#[expect(
45+
clippy::expect_used,
46+
reason = "cpu.stat lines from the kernel are guaranteed by the cgroup v2 interface to have key/value pairs; deviation indicates a kernel ABI break"
47+
)]
4448
pub(crate) async fn poll(
4549
&mut self,
4650
group_prefix: &Path,

lading/src/observer/linux/procfs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ impl Sampler {
186186
clippy::cast_possible_truncation,
187187
clippy::cast_possible_wrap
188188
)]
189+
#[expect(
190+
clippy::expect_used,
191+
reason = "process_info is populated for every pid before handle_process is called; a missing entry here indicates a programming error in the sampler driver"
192+
)]
189193
async fn handle_process(
190194
&mut self,
191195
process: Process,
@@ -375,6 +379,10 @@ async fn proc_comm(pid: i32) -> Result<String, Error> {
375379

376380
/// Collect the 'name' of the process. This is pulled from `/proc/<pid>/exe` and
377381
/// we take the last part of that, like posix `top` does.
382+
#[expect(
383+
clippy::expect_used,
384+
reason = "Linux exe symlink targets are valid UTF-8 paths in all real-world cases; non-UTF-8 indicates a non-standard filesystem encoding"
385+
)]
378386
async fn proc_exe(pid: i32) -> Result<String, Error> {
379387
let exe_path = format!("/proc/{pid}/exe");
380388
let exe = tokio::fs::read_link(&exe_path).await?;

lading/src/observer/linux/procfs/memory/smaps.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ impl Regions {
320320
map.into_iter().collect()
321321
}
322322

323+
#[expect(
324+
clippy::expect_used,
325+
reason = "compile-time-constant regex literal; failure to compile is a programming error caught in tests"
326+
)]
323327
fn into_region_strs(contents: &str) -> Vec<&str> {
324328
let mut str_regions = Vec::new();
325329
// Split the smaps file into regions

lading/src/target.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ impl Server {
201201

202202
/// Watch a container running elsewhere on the system. lading will report an
203203
/// error if the container exits before the test completes.
204+
#[expect(
205+
clippy::expect_used,
206+
reason = "container PIDs fit in i32 on supported platforms; a failure indicates a platform invariant violation"
207+
)]
204208
async fn watch_container(
205209
config: DockerConfig,
206210
pid_snd: TargetPidSender,
@@ -374,6 +378,10 @@ impl Server {
374378

375379
/// Execute a binary target. lading will attempt to gracefully terminate the
376380
/// process after the test has completed.
381+
#[expect(
382+
clippy::expect_used,
383+
reason = "child PIDs returned by tokio::process::Command fit in i32 on supported platforms; a failure indicates a platform invariant violation"
384+
)]
377385
async fn execute_binary(
378386
config: BinaryConfig,
379387
pid_snd: TargetPidSender,

lading/src/target_metrics/expvar.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ impl Expvar {
7272
/// # Panics
7373
///
7474
/// None are known.
75+
#[expect(
76+
clippy::expect_used,
77+
reason = "reqwest::ClientBuilder::build fails only on TLS backend setup; an unrecoverable bootstrap failure"
78+
)]
7579
pub(crate) async fn run(self) -> Result<(), Error> {
7680
info!("Expvar target metrics scraper running, but waiting for warmup to complete");
7781
self.experiment_started.recv().await; // block until experimental lading_signal::Watcher entered

lading/src/target_metrics/prometheus.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ use tracing::{error, info, trace, warn};
1515

1616
// Regex to match Prometheus label pairs: label_name="label_value"
1717
// The value can be empty (e.g., label="")
18+
#[expect(
19+
clippy::expect_used,
20+
reason = "compile-time-constant regex literal; failure to compile is a programming error caught in tests"
21+
)]
1822
static LABEL_REGEX: Lazy<Regex> =
1923
Lazy::new(|| Regex::new(r#"(\w+)="([^"]*)""#).expect("Failed to compile label regex"));
2024

@@ -179,6 +183,10 @@ pub(crate) async fn scrape_metrics(
179183
clippy::cast_possible_truncation,
180184
clippy::cast_sign_loss
181185
)]
186+
#[expect(
187+
clippy::expect_used,
188+
reason = "FIXME: this is an ad-hoc Prometheus parser that panics on malformed input; reported parse failures should surface as recoverable errors. Tracked for follow-up."
189+
)]
182190
pub(crate) fn parse_prometheus_metrics(
183191
text: &str,
184192
tags: Option<&FxHashMap<String, String>>,

0 commit comments

Comments
 (0)