Skip to content

Commit e141480

Browse files
hyperpolymathclaude
andcommitted
fix(conative-gating): sweep .expect("TODO: handle error") — 76 sites cleared
Replaced all 76 occurrences of `.expect("TODO: handle error")` with context-appropriate patterns: - 7 in slm/src/lib.rs (test code) → `.unwrap()` - 9 in src/main.rs (JSON serialization) → `.expect("invariant: JSON serialization of struct cannot fail")` - 25 in src/oracle/src/lib.rs (test code) → `.unwrap()` - 35 in src/contract/src/lib.rs (test code) → `.unwrap()` Tests: 49 passed / 0 failed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 591500c commit e141480

4 files changed

Lines changed: 76 additions & 76 deletions

File tree

src/contract/src/lib.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ mod tests {
15391539
"fn main() { println!(\"Hello\"); }",
15401540
));
15411541

1542-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1542+
let decision = runner.evaluate(&request).unwrap();
15431543
assert_eq!(decision.verdict, Verdict::Allow);
15441544
assert!(decision.refusal.is_none());
15451545
}
@@ -1552,11 +1552,11 @@ mod tests {
15521552
"export const foo: string = 'bar';",
15531553
));
15541554

1555-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1555+
let decision = runner.evaluate(&request).unwrap();
15561556
assert_eq!(decision.verdict, Verdict::Block);
15571557
assert!(decision.refusal.is_some());
15581558

1559-
let refusal = decision.refusal.expect("TODO: handle error");
1559+
let refusal = decision.refusal.unwrap();
15601560
assert_eq!(refusal.category, RefusalCategory::ForbiddenLanguage);
15611561
assert_eq!(refusal.code, RefusalCode::Lang100TypeScript);
15621562
}
@@ -1569,10 +1569,10 @@ mod tests {
15691569
r#"let password = "supersecret123456""#,
15701570
));
15711571

1572-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1572+
let decision = runner.evaluate(&request).unwrap();
15731573
assert_eq!(decision.verdict, Verdict::Block);
15741574

1575-
let refusal = decision.refusal.expect("TODO: handle error");
1575+
let refusal = decision.refusal.unwrap();
15761576
assert_eq!(refusal.category, RefusalCategory::ForbiddenPattern);
15771577
}
15781578

@@ -1581,7 +1581,7 @@ mod tests {
15811581
let runner = ContractRunner::new();
15821582
let request = GatingRequest::new(create_proposal("src/lib.rs", "pub fn hello() {}"));
15831583

1584-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1584+
let decision = runner.evaluate(&request).unwrap();
15851585
let audit = runner.audit(&request, &decision);
15861586

15871587
assert_eq!(audit.request_id, request.request_id);
@@ -1638,7 +1638,7 @@ mod tests {
16381638
"import os\ndef configure(): pass",
16391639
));
16401640

1641-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1641+
let decision = runner.evaluate(&request).unwrap();
16421642
assert_eq!(decision.verdict, Verdict::Allow);
16431643
}
16441644

@@ -1650,8 +1650,8 @@ mod tests {
16501650
let request1 = GatingRequest::new(create_proposal("a.rs", "fn main() {}"));
16511651
let request2 = GatingRequest::new(create_proposal("b.rs", "fn main() {}"));
16521652

1653-
let decision1 = runner.evaluate(&request1).expect("TODO: handle error");
1654-
let decision2 = runner.evaluate(&request2).expect("TODO: handle error");
1653+
let decision1 = runner.evaluate(&request1).unwrap();
1654+
let decision2 = runner.evaluate(&request2).unwrap();
16551655

16561656
assert_ne!(decision1.decision_id, decision2.decision_id);
16571657
assert_ne!(decision1.request_id, decision2.request_id);
@@ -1693,7 +1693,7 @@ mod tests {
16931693
fn test_contract_runner_default() {
16941694
let runner = ContractRunner::default();
16951695
let request = GatingRequest::new(create_proposal("lib.rs", "pub fn foo() {}"));
1696-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1696+
let decision = runner.evaluate(&request).unwrap();
16971697
assert_eq!(decision.verdict, Verdict::Allow);
16981698
}
16991699

@@ -1721,10 +1721,10 @@ mod tests {
17211721
"const x: string = 'hello';",
17221722
));
17231723

1724-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1724+
let decision = runner.evaluate(&request).unwrap();
17251725
assert!(decision.refusal.is_some());
17261726

1727-
let refusal = decision.refusal.expect("TODO: handle error");
1727+
let refusal = decision.refusal.unwrap();
17281728
assert!(!refusal.evidence.is_empty());
17291729
assert_eq!(refusal.evidence[0].evidence_type, EvidenceType::ContentMarker);
17301730
}
@@ -1737,10 +1737,10 @@ mod tests {
17371737
"import os",
17381738
));
17391739

1740-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1741-
let refusal = decision.refusal.expect("TODO: handle error");
1740+
let decision = runner.evaluate(&request).unwrap();
1741+
let refusal = decision.refusal.unwrap();
17421742
assert!(refusal.remediation.is_some());
1743-
assert!(refusal.remediation.expect("TODO: handle error").contains("only allowed in salt"));
1743+
assert!(refusal.remediation.unwrap().contains("only allowed in salt"));
17441744
}
17451745

17461746
#[test]
@@ -1751,19 +1751,19 @@ mod tests {
17511751
"package main\nfunc main() {}",
17521752
));
17531753

1754-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1755-
let refusal = decision.refusal.expect("TODO: handle error");
1754+
let decision = runner.evaluate(&request).unwrap();
1755+
let refusal = decision.refusal.unwrap();
17561756
assert_eq!(refusal.code, RefusalCode::Lang102Go);
17571757
assert!(refusal.remediation.is_some());
1758-
assert!(refusal.remediation.expect("TODO: handle error").contains("Rust"));
1758+
assert!(refusal.remediation.unwrap().contains("Rust"));
17591759
}
17601760

17611761
#[test]
17621762
fn test_contract_evaluator_records_oracle_stage() {
17631763
let runner = ContractRunner::new();
17641764
let request = GatingRequest::new(create_proposal("lib.rs", "pub fn foo() {}"));
17651765

1766-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1766+
let decision = runner.evaluate(&request).unwrap();
17671767
assert!(decision.processing.stages_executed.contains(&"oracle".to_string()));
17681768
assert!(decision.evaluations.oracle.is_some());
17691769
}
@@ -1773,7 +1773,7 @@ mod tests {
17731773
let runner = ContractRunner::new();
17741774
let request = GatingRequest::new(create_proposal("lib.rs", "pub fn foo() {}"));
17751775

1776-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1776+
let decision = runner.evaluate(&request).unwrap();
17771777
assert!(decision.processing.duration_us > 0);
17781778
}
17791779

@@ -1795,20 +1795,20 @@ mod tests {
17951795
fn test_audit_entry_json_serialization() {
17961796
let runner = ContractRunner::new();
17971797
let request = GatingRequest::new(create_proposal("lib.rs", "pub fn foo() {}"));
1798-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1798+
let decision = runner.evaluate(&request).unwrap();
17991799
let audit = runner.audit(&request, &decision);
18001800

18011801
let json = audit.to_json();
18021802
assert!(json.is_ok());
1803-
let json_str = json.expect("TODO: handle error");
1803+
let json_str = json.unwrap();
18041804
assert!(json_str.contains("\"verdict\""));
18051805
}
18061806

18071807
#[test]
18081808
fn test_audit_entry_compact_json() {
18091809
let runner = ContractRunner::new();
18101810
let request = GatingRequest::new(create_proposal("lib.rs", "pub fn foo() {}"));
1811-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1811+
let decision = runner.evaluate(&request).unwrap();
18121812
let audit = runner.audit(&request, &decision);
18131813

18141814
let json = audit.to_json_compact();
@@ -1819,7 +1819,7 @@ mod tests {
18191819
fn test_audit_entry_pretty_json() {
18201820
let runner = ContractRunner::new();
18211821
let request = GatingRequest::new(create_proposal("lib.rs", "pub fn foo() {}"));
1822-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1822+
let decision = runner.evaluate(&request).unwrap();
18231823
let audit = runner.audit(&request, &decision);
18241824

18251825
let json = audit.to_json_pretty();
@@ -1948,7 +1948,7 @@ mod tests {
19481948
let json = baseline.to_json();
19491949
assert!(json.is_ok());
19501950

1951-
let json_str = json.expect("TODO: handle error");
1951+
let json_str = json.unwrap();
19521952
let parsed = RegressionBaseline::from_json(&json_str);
19531953
assert!(parsed.is_ok());
19541954
}
@@ -1980,7 +1980,7 @@ mod tests {
19801980
"defmodule MyModule, do: :ok",
19811981
));
19821982

1983-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1983+
let decision = runner.evaluate(&request).unwrap();
19841984
// Should be allowed as tier1 language
19851985
assert!(matches!(decision.verdict, Verdict::Allow),
19861986
"Elixir should be allowed, got {:?}", decision.verdict);
@@ -1994,7 +1994,7 @@ mod tests {
19941994
"const std = @import(\"std\");\npub fn main() void {}",
19951995
));
19961996

1997-
let decision = runner.evaluate(&request).expect("TODO: handle error");
1997+
let decision = runner.evaluate(&request).unwrap();
19981998
assert_eq!(decision.verdict, Verdict::Allow);
19991999
}
20002000

@@ -2006,7 +2006,7 @@ mod tests {
20062006
"@react.component\nlet make = () => React.string(\"Hello\")",
20072007
));
20082008

2009-
let decision = runner.evaluate(&request).expect("TODO: handle error");
2009+
let decision = runner.evaluate(&request).unwrap();
20102010
assert_eq!(decision.verdict, Verdict::Allow);
20112011
}
20122012

@@ -2018,7 +2018,7 @@ mod tests {
20182018
"procedure Main is\nbegin\n null;\nend Main;",
20192019
));
20202020

2021-
let decision = runner.evaluate(&request).expect("TODO: handle error");
2021+
let decision = runner.evaluate(&request).unwrap();
20222022
assert_eq!(decision.verdict, Verdict::Allow);
20232023
}
20242024

@@ -2030,7 +2030,7 @@ mod tests {
20302030
"module Main where\nmain = putStrLn \"Hello\"",
20312031
));
20322032

2033-
let decision = runner.evaluate(&request).expect("TODO: handle error");
2033+
let decision = runner.evaluate(&request).unwrap();
20342034
assert_eq!(decision.verdict, Verdict::Allow);
20352035
}
20362036

@@ -2042,9 +2042,9 @@ mod tests {
20422042
r#"{"name": "test", "version": "1.0.0"}"#,
20432043
));
20442044

2045-
let decision = runner.evaluate(&request).expect("TODO: handle error");
2045+
let decision = runner.evaluate(&request).unwrap();
20462046
assert_eq!(decision.verdict, Verdict::Block);
2047-
let refusal = decision.refusal.expect("TODO: handle error");
2047+
let refusal = decision.refusal.unwrap();
20482048
assert_eq!(refusal.code, RefusalCode::Tool200NpmWithoutDeno);
20492049
}
20502050

@@ -2057,7 +2057,7 @@ mod tests {
20572057
));
20582058
request.proposal.files_affected.push("deno.json".to_string());
20592059

2060-
let decision = runner.evaluate(&request).expect("TODO: handle error");
2060+
let decision = runner.evaluate(&request).unwrap();
20612061
assert_eq!(decision.verdict, Verdict::Allow);
20622062
}
20632063

src/main.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ fn scan_directory(
563563
Ok(result) => {
564564
match format {
565565
OutputFormat::Json => {
566-
println!("{}", serde_json::to_string_pretty(&result).expect("TODO: handle error"));
566+
println!("{}", serde_json::to_string_pretty(&result).expect("invariant: JSON serialization of struct cannot fail"));
567567
}
568568
OutputFormat::Compact => {
569569
let status = if !result.violations.is_empty() {
@@ -675,7 +675,7 @@ fn check_content(
675675
Ok(result) => {
676676
match format {
677677
OutputFormat::Json => {
678-
println!("{}", serde_json::to_string_pretty(&result).expect("TODO: handle error"));
678+
println!("{}", serde_json::to_string_pretty(&result).expect("invariant: JSON serialization of struct cannot fail"));
679679
}
680680
OutputFormat::Compact => {
681681
let status = if !result.violations.is_empty() {
@@ -741,7 +741,7 @@ fn show_policy(format: &OutputFormat, section: Option<&str>) {
741741

742742
match format {
743743
OutputFormat::Json => {
744-
println!("{}", serde_json::to_string_pretty(&policy).expect("TODO: handle error"));
744+
println!("{}", serde_json::to_string_pretty(&policy).expect("invariant: JSON serialization of struct cannot fail"));
745745
}
746746
OutputFormat::Compact => {
747747
println!(
@@ -825,7 +825,7 @@ fn validate_proposal(
825825
Ok(result) => {
826826
match format {
827827
OutputFormat::Json | OutputFormat::Compact => {
828-
println!("{}", serde_json::to_string_pretty(&result).expect("TODO: handle error"));
828+
println!("{}", serde_json::to_string_pretty(&result).expect("invariant: JSON serialization of struct cannot fail"));
829829
}
830830
OutputFormat::Text => {
831831
println!("Proposal: {}", result.proposal_id);
@@ -989,7 +989,7 @@ fn run_contract_tests(
989989

990990
match format {
991991
OutputFormat::Json => {
992-
println!("{}", serde_json::to_string_pretty(&summary).expect("TODO: handle error"));
992+
println!("{}", serde_json::to_string_pretty(&summary).expect("invariant: JSON serialization of struct cannot fail"));
993993
}
994994
OutputFormat::Compact => {
995995
println!(
@@ -1186,10 +1186,10 @@ fn eval_contract_request(request_path: &Path, format: &OutputFormat, include_aud
11861186
decision: decision.clone(),
11871187
audit
11881188
})
1189-
.expect("TODO: handle error")
1189+
.expect("invariant: JSON serialization of struct cannot fail")
11901190
);
11911191
} else {
1192-
println!("{}", serde_json::to_string_pretty(&decision).expect("TODO: handle error"));
1192+
println!("{}", serde_json::to_string_pretty(&decision).expect("invariant: JSON serialization of struct cannot fail"));
11931193
}
11941194
}
11951195
OutputFormat::Compact => {
@@ -1223,7 +1223,7 @@ fn eval_contract_request(request_path: &Path, format: &OutputFormat, include_aud
12231223
if include_audit {
12241224
let audit = runner.audit(&request, &decision);
12251225
println!("\nAudit Log Entry:");
1226-
println!("{}", serde_json::to_string_pretty(&audit).expect("TODO: handle error"));
1226+
println!("{}", serde_json::to_string_pretty(&audit).expect("invariant: JSON serialization of struct cannot fail"));
12271227
}
12281228
}
12291229
}
@@ -1324,7 +1324,7 @@ fn show_contract_schema(format: &OutputFormat, section: Option<&str>) {
13241324
],
13251325
};
13261326

1327-
println!("{}", serde_json::to_string_pretty(&schema).expect("TODO: handle error"));
1327+
println!("{}", serde_json::to_string_pretty(&schema).expect("invariant: JSON serialization of struct cannot fail"));
13281328
}
13291329
OutputFormat::Compact | OutputFormat::Text => {
13301330
let show_all = section.is_none();
@@ -1515,7 +1515,7 @@ fn run_redteam_tests(
15151515

15161516
match format {
15171517
OutputFormat::Json => {
1518-
println!("{}", serde_json::to_string_pretty(&summary).expect("TODO: handle error"));
1518+
println!("{}", serde_json::to_string_pretty(&summary).expect("invariant: JSON serialization of struct cannot fail"));
15191519
}
15201520
OutputFormat::Compact => {
15211521
println!(
@@ -1767,7 +1767,7 @@ fn run_regression_tests(
17671767

17681768
match format {
17691769
OutputFormat::Json => {
1770-
println!("{}", serde_json::to_string_pretty(&report).expect("TODO: handle error"));
1770+
println!("{}", serde_json::to_string_pretty(&report).expect("invariant: JSON serialization of struct cannot fail"));
17711771
}
17721772
OutputFormat::Compact => {
17731773
println!(

0 commit comments

Comments
 (0)