feat(context_window): replace ? operator with explicit match + tracing::warn!#118
Conversation
…g::warn! Replace the three ? operators in render_used_tokens with explicit match arms per CLAUDE.md convention: absent data → explicit match + tracing::warn! + None. - ctx.context_window absent: silent None (expected pre-data, AC3) - cw.current_usage absent: silent None (expected pre-call, AC1) - cw.context_window_size absent with current_usage present: tracing::warn! + None (AC2) Add three unit test cases covering all ACs; suppress clippy::question_mark for intentional silent-None match arms. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
test |
Code reviewCLAUDE.md violation: silent In cship/src/modules/context_window.rs Lines 180 to 189 in fbd5fbe Per
The rule draws a single binary distinction — only the disabled-flag path is explicitly permitted to be silent. There is no carveout for "expected pre-data states." Every other render function in the same file ( Suggested fix: Add let cw = match ctx.context_window.as_ref() {
Some(cw) => cw,
None => {
tracing::warn!(
"cship.context_window.used_tokens: context_window absent from context"
);
return None;
}
};
let cu = match cw.current_usage.as_ref() {
Some(cu) => cu,
None => {
tracing::warn!(
"cship.context_window.used_tokens: current_usage absent from context_window"
);
return None;
}
};
|
…_used_tokens Addresses PR #118 review: both context_window and current_usage absent-data arms now emit tracing::warn! per CLAUDE.md policy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
?operators inrender_used_tokenswith explicitmatcharms following the project's CLAUDE.md conventioncontext_windowabsent → silentNone(expected pre-data state)current_usageabsent → silentNone(expected pre-call state)context_window_sizeabsent whencurrent_usageisSome→tracing::warn!+None#[allow(clippy::question_mark)]to suppress false-positive lint on intentional silent-None patternsTest plan
test_used_tokens_absent_current_usage_returns_none_silently— AC1test_used_tokens_absent_context_window_size_returns_none— AC2test_absent_context_window_returns_noneto coverrender_used_tokens— AC3cargo clippy -- -D warningscleancargo fmt --checkcleancargo install --path .succeeds🤖 Generated with Claude Code