Skip to content

Commit 0d11476

Browse files
hyperpolymathclaude
andcommitted
fix: restructure prod expect("TODO") sites in vext-email-gateway + lazy-eliminator
Closes the bulk-rewrite anti-pattern (.unwrap() -> .expect("TODO: handle error")) for production code: identical panic + fake debt marker. Per estate per-site policy: - vext-email-gateway/src/main.rs (5 sites): map_err to VextError variants for parse() of caller-supplied addresses + env-var-derived port. Static literal "Vext <noreply@vext.org>" keeps .expect() with explicit WHY message documenting the unreachable branch (policy e). - lazy-eliminator/src/patterns.rs (19 sites): all Regex::new() on static literal patterns; rewrite expect message to document why the panic is unreachable (verified by tests). Restructure to OnceLock would change call semantics; the documented invariant is policy e. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f4cb2af commit 0d11476

2 files changed

Lines changed: 34 additions & 24 deletions

File tree

lazy-eliminator/src/patterns.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,37 @@ fn todo_patterns() -> Vec<Pattern> {
3535
vec![
3636
Pattern {
3737
kind: IncompletenessKind::TodoComment,
38-
regex: Regex::new(r"(?i)//\s*TODO[:\s]").expect("TODO: handle error"),
38+
regex: Regex::new(r"(?i)//\s*TODO[:\s]").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
3939
description: "C-style TODO comment",
4040
},
4141
Pattern {
4242
kind: IncompletenessKind::TodoComment,
43-
regex: Regex::new(r"(?i)#\s*TODO[:\s]").expect("TODO: handle error"),
43+
regex: Regex::new(r"(?i)#\s*TODO[:\s]").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
4444
description: "Hash-style TODO comment",
4545
},
4646
Pattern {
4747
kind: IncompletenessKind::TodoComment,
48-
regex: Regex::new(r"(?i)/\*\s*TODO[:\s]").expect("TODO: handle error"),
48+
regex: Regex::new(r"(?i)/\*\s*TODO[:\s]").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
4949
description: "Block comment TODO",
5050
},
5151
Pattern {
5252
kind: IncompletenessKind::PlaceholderText,
53-
regex: Regex::new(r"\.\.\.").expect("TODO: handle error"),
53+
regex: Regex::new(r"\.\.\.").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
5454
description: "Ellipsis placeholder",
5555
},
5656
Pattern {
5757
kind: IncompletenessKind::PlaceholderText,
58-
regex: Regex::new(r"<placeholder>").expect("TODO: handle error"),
58+
regex: Regex::new(r"<placeholder>").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
5959
description: "Explicit placeholder tag",
6060
},
6161
Pattern {
6262
kind: IncompletenessKind::TruncationMarker,
63-
regex: Regex::new(r"//\s*\.\.\.\s*\(truncated\)").expect("TODO: handle error"),
63+
regex: Regex::new(r"//\s*\.\.\.\s*\(truncated\)").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
6464
description: "Truncation marker",
6565
},
6666
Pattern {
6767
kind: IncompletenessKind::TruncationMarker,
68-
regex: Regex::new(r"//\s*rest similar").expect("TODO: handle error"),
68+
regex: Regex::new(r"//\s*rest similar").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
6969
description: "Rest similar marker",
7070
},
7171
]
@@ -75,12 +75,12 @@ fn python_patterns() -> Vec<Pattern> {
7575
vec![
7676
Pattern {
7777
kind: IncompletenessKind::UnimplementedCode,
78-
regex: Regex::new(r"\braise\s+NotImplementedError\b").expect("TODO: handle error"),
78+
regex: Regex::new(r"\braise\s+NotImplementedError\b").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
7979
description: "Python NotImplementedError",
8080
},
8181
Pattern {
8282
kind: IncompletenessKind::NullImplementation,
83-
regex: Regex::new(r"^\s*pass\s*$").expect("TODO: handle error"),
83+
regex: Regex::new(r"^\s*pass\s*$").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
8484
description: "Python pass statement",
8585
},
8686
]
@@ -90,17 +90,17 @@ fn rust_patterns() -> Vec<Pattern> {
9090
vec![
9191
Pattern {
9292
kind: IncompletenessKind::UnimplementedCode,
93-
regex: Regex::new(r"\bunimplemented!\(").expect("TODO: handle error"),
93+
regex: Regex::new(r"\bunimplemented!\(").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
9494
description: "Rust unimplemented! macro",
9595
},
9696
Pattern {
9797
kind: IncompletenessKind::UnimplementedCode,
98-
regex: Regex::new(r"\btodo!\(").expect("TODO: handle error"),
98+
regex: Regex::new(r"\btodo!\(").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
9999
description: "Rust todo! macro",
100100
},
101101
Pattern {
102102
kind: IncompletenessKind::UnimplementedCode,
103-
regex: Regex::new(r"\bunreachable!\(").expect("TODO: handle error"),
103+
regex: Regex::new(r"\bunreachable!\(").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
104104
description: "Rust unreachable! macro",
105105
},
106106
]
@@ -110,17 +110,17 @@ fn javascript_patterns() -> Vec<Pattern> {
110110
vec![
111111
Pattern {
112112
kind: IncompletenessKind::UnimplementedCode,
113-
regex: Regex::new(r#"throw\s+new\s+Error\(\s*["'](?:unimplemented|not implemented)["']\s*\)"#).expect("TODO: handle error"),
113+
regex: Regex::new(r#"throw\s+new\s+Error\(\s*["'](?:unimplemented|not implemented)["']\s*\)"#).expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
114114
description: "JavaScript unimplemented error",
115115
},
116116
Pattern {
117117
kind: IncompletenessKind::NullImplementation,
118-
regex: Regex::new(r"return\s+null\s*;").expect("TODO: handle error"),
118+
regex: Regex::new(r"return\s+null\s*;").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
119119
description: "Return null",
120120
},
121121
Pattern {
122122
kind: IncompletenessKind::NullImplementation,
123-
regex: Regex::new(r"^\s*\{\s*\}\s*$").expect("TODO: handle error"),
123+
regex: Regex::new(r"^\s*\{\s*\}\s*$").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
124124
description: "Empty block",
125125
},
126126
]
@@ -130,12 +130,12 @@ fn java_patterns() -> Vec<Pattern> {
130130
vec![
131131
Pattern {
132132
kind: IncompletenessKind::UnimplementedCode,
133-
regex: Regex::new(r#"throw\s+new\s+UnsupportedOperationException\(\s*["'].*not.*implemented.*["']\s*\)"#).expect("TODO: handle error"),
133+
regex: Regex::new(r#"throw\s+new\s+UnsupportedOperationException\(\s*["'].*not.*implemented.*["']\s*\)"#).expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
134134
description: "Java UnsupportedOperationException",
135135
},
136136
Pattern {
137137
kind: IncompletenessKind::NullImplementation,
138-
regex: Regex::new(r"return\s+null\s*;").expect("TODO: handle error"),
138+
regex: Regex::new(r"return\s+null\s*;").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
139139
description: "Return null",
140140
},
141141
]
@@ -145,12 +145,12 @@ fn go_patterns() -> Vec<Pattern> {
145145
vec![
146146
Pattern {
147147
kind: IncompletenessKind::UnimplementedCode,
148-
regex: Regex::new(r#"panic\(\s*["']not implemented["']\s*\)"#).expect("TODO: handle error"),
148+
regex: Regex::new(r#"panic\(\s*["']not implemented["']\s*\)"#).expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
149149
description: "Go panic(\"not implemented\")",
150150
},
151151
Pattern {
152152
kind: IncompletenessKind::NullImplementation,
153-
regex: Regex::new(r"return\s+nil").expect("TODO: handle error"),
153+
regex: Regex::new(r"return\s+nil").expect("static regex literal in patterns.rs is well-formed (verified by tests)"),
154154
description: "Return nil",
155155
},
156156
]

vext-email-gateway/src/main.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,13 @@ impl Gateway {
247247
msg.id,
248248
);
249249

250+
let from_addr = "Vext <noreply@vext.org>".parse()
251+
.expect("static literal 'Vext <noreply@vext.org>' is a valid mailbox");
252+
let to_addr = to.parse()
253+
.map_err(|e: lettre::address::AddressError| VextError::InvalidEmail(e.to_string()))?;
250254
let email = EmailMessage::builder()
251-
.from(format!("Vext <noreply@vext.org>").parse().expect("TODO: handle error"))
252-
.to(to.parse().expect("TODO: handle error"))
255+
.from(from_addr)
256+
.to(to_addr)
253257
.subject(msg.title.clone().unwrap_or_else(|| "Vext message".to_string()))
254258
.header(header::ContentType::TEXT_PLAIN)
255259
.body(body)
@@ -263,9 +267,13 @@ impl Gateway {
263267

264268
/// Send simple text email
265269
async fn send_simple_email(&self, to: &str, subject: &str, body: &str) -> Result<()> {
270+
let from_addr = "Vext <noreply@vext.org>".parse()
271+
.expect("static literal 'Vext <noreply@vext.org>' is a valid mailbox");
272+
let to_addr = to.parse()
273+
.map_err(|e: lettre::address::AddressError| VextError::InvalidEmail(e.to_string()))?;
266274
let email = EmailMessage::builder()
267-
.from("Vext <noreply@vext.org>".parse().expect("TODO: handle error"))
268-
.to(to.parse().expect("TODO: handle error"))
275+
.from(from_addr)
276+
.to(to_addr)
269277
.subject(subject)
270278
.header(header::ContentType::TEXT_PLAIN)
271279
.body(body.to_string())
@@ -315,7 +323,9 @@ async fn main() -> Result<()> {
315323
smtp_port: std::env::var("SMTP_PORT")
316324
.unwrap_or_else(|_| "587".to_string())
317325
.parse()
318-
.expect("TODO: handle error"),
326+
.map_err(|e: std::num::ParseIntError| {
327+
VextError::Validation(format!("SMTP_PORT must be a valid u16: {}", e))
328+
})?,
319329
smtp_username: std::env::var("SMTP_USERNAME")
320330
.expect("SMTP_USERNAME required"),
321331
smtp_password: std::env::var("SMTP_PASSWORD")

0 commit comments

Comments
 (0)