refactor(payload): retire remaining .expect() sites and drop quarantine#1893
Draft
goxberry wants to merge 1 commit into
Draft
Conversation
Closes out the `lading_payload` Cat-2 cleanup. 17 production `.expect()`
sites are addressed and the crate-root `#![allow(clippy::expect_used)]`
quarantine is removed from `lading_payload/src/lib.rs`. The workspace
`clippy::expect_used = "deny"` now applies in full.
13 sites become `.unwrap_or_else(... unreachable!("..."))`:
- `templated_json/generator.rs:186` (NonZeroI64 after documented
positivity invariant)
- `templated_json/config.rs:288` (serde_json on a `&str`)
- `templated_json/config.rs:443` (parts.last() after `str::split`)
- `dogstatsd/metric.rs:149` (ZeroToOne after `clamp(0.0, 1.0)`)
- `dogstatsd/metric.rs:263` (Vec::pop after known push)
- `syslog.rs:75-76` (timestamp in [2020, 2030] within OffsetDateTime range)
- `syslog.rs:77` (RFC-3339 format of valid OffsetDateTime)
- `syslog.rs:87` (serde_json on primitive-field struct)
- `datadog_logs.rs:57` (str_pool of_size_range; pool sized 1_000_000)
- `datadog_logs.rs:60` (serde_json on primitive-field struct)
- `fluent.rs:129,135` (same pool pattern)
- `random_string_pool.rs:189` (pool sized by caller convention)
4 sites in `dogstatsd/` are annotated `#[expect(clippy::expect_used,
reason = "...")]` at the function level because the panic is the
documented contract when upstream config validation is too loose:
- `dogstatsd/metric.rs::MetricGenerator::generate` — choose template_idx
from `0..self.templates.len()`; empty `templates` is a serious logic
bug, matching the existing `SAFETY:` comment.
- `dogstatsd/service_check.rs::ServiceCheckGenerator::generate` — same
shape for `self.names`.
- `dogstatsd/common.rs::NumValueGenerator::new` — `Uniform::new_inclusive`
on `ConfRange::Inclusive { min, max }`, which does not validate
`min <= max` at deserialization; a misconfigured config panics here
with the existing diagnostic message.
No runtime behavior change.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 22, 2026
Contributor
Author
This was referenced May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does this PR do?
Closes out the
lading_payload.expect()cleanup stack. The crate-root#![allow(clippy::expect_used)]quarantine is removed fromlading_payload/src/lib.rs, and the remaining 17 production.expect()sites are addressed.lading_payloadis now fully covered by the workspace-levelclippy::expect_used = "deny".Sites covered
13 sites →
.unwrap_or_else(... unreachable!("..."))(structural infallibles)templated_json/generator.rs:186NonZeroI64::new(new_ms)// the error branch is unreachable in practicecomment documents the positivity invarianttemplated_json/config.rs:288serde_json::to_string(s)on a&strtemplated_json/config.rs:443parts.last()afterstr::splitstr::splitalways yields ≥1 partdogstatsd/metric.rs:149ZeroToOne::try_from(sample_rate)afterclamp(0.0, 1.0)dogstatsd/metric.rs:263values.pop()after a knownvalues.push(value)100+ lines abovesyslog.rs:75-76OffsetDateTime::from_unix_timestamp(base_ts + offset)[2020, 2030]is well inside the validOffsetDateTimerangesyslog.rs:77.format(&Rfc3339)of a validOffsetDateTimesyslog.rs:87serde_json::to_string(&rng.random::<Message>())Messageis a struct of primitive fields with derivedSerializedatadog_logs.rs:57str_pool.of_size_range(rng, 1_u8..16)datadog_logs.rs:60serde_json::to_string(&rng.random::<Structured>())Messagefluent.rs:129, 135str_pool.of_size_range(rng, 1_u8..16)common/strings/random_string_pool.rs:189pool.of_size(rng, sz)length_range4 sites → fn-level
#[expect(clippy::expect_used, reason = "...")](panic is the documented contract)dogstatsd/metric.rs::MetricGenerator::generateself.templatesis validated non-empty at construction; an emptytemplatesvec here is a serious logic bug, as documented by the existingSAFETY:commentdogstatsd/service_check.rs::ServiceCheckGenerator::generateself.namesis validated non-empty at constructiondogstatsd/common.rs::NumValueGenerator::newUniform::new_inclusive(min, max)fails whenmin > max.ConfRange::Inclusive { min, max }does not validatemin ≤ maxat deserialization; a misconfigured config panics here with the existing diagnostic messageQuarantine removed
The
#![allow(clippy::expect_used)]line is removed fromlading_payload/src/lib.rs. From here on, any new.expect()in production code in this crate is a hard CI failure.Motivation
Final PR in the
lading_payloadcleanup sub-stack. The stack started by #1882:lading_throttlequarantine?-context infallibles)#[expect]for handle contracts)Block::arbitrary)lading_payloadquarantine (this PR)After this lands, the only crates still carrying a quarantine are
lading_capture(149 sites) andlading(243 sites), which are addressed in later sub-stacks.Related issues
Stacked on #1892.
Additional Notes
cargo build --all-targets --all-features✓bash ci/validate✓ (full: shellcheck, fmt, check, custom lints, clippy, deny, config validation, nextest, loom, kani, buf)cargo clippy -p lading-payload --all-targets --all-features 2>&1 | grep -c expect_used→ 0 (verifies the quarantine drop is safe)Note on parent PRs
While preparing this PR I noticed PRs #1885, #1890, #1891, and #1892 had
fmtCI failures from earlier (cargo fmt --checkwhitespace) that I missed by runningci/clippyinstead ofci/validateper branch. Those PRs have been force-pushed with formatting fixes. The changes are pure whitespace and don't touch semantics.