Skip to content

Commit 48d7030

Browse files
hyperpolymathclaude
andcommitted
fix(rust): replace .expect("TODO") in codegen/parser.rs (2 prod + 6 tests)
8 .expect("TODO: handle error") sites in src/codegen/parser.rs cleared. Prod (2 sites in parse_create_table): Line 143: upper.find("IF NOT EXISTS") — guarded by the surrounding `if upper.contains("IF NOT EXISTS")` (line 141), so find returns Some. Line 147: upper.find("TABLE") — parse_create_table is only invoked when upper.starts_with("CREATE TABLE") at parse_sql_schema:100, so "TABLE" is always present. Both expect messages document the invariant — SPARK proof candidates per estate-wide direction. Tests (6 sites): all parse_sql_schema(...) calls inside #[cfg(test)] mod revert to .unwrap(). cargo test --lib: 26/26 green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e62f95a commit 48d7030

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/codegen/parser.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,15 @@ fn parse_create_table(statement: &str) -> Result<Option<TableDef>> {
140140
let _before_paren = statement[..paren_start].trim();
141141
let name_part = if upper.contains("IF NOT EXISTS") {
142142
// Skip past "CREATE TABLE IF NOT EXISTS".
143-
let idx = upper.find("IF NOT EXISTS").expect("TODO: handle error") + "IF NOT EXISTS".len();
143+
let idx = upper.find("IF NOT EXISTS")
144+
.expect("upper.contains(\"IF NOT EXISTS\") was guarded immediately above, so find() is always Some")
145+
+ "IF NOT EXISTS".len();
144146
statement[idx..paren_start].trim()
145147
} else {
146148
// Skip past "CREATE TABLE".
147-
let idx = upper.find("TABLE").expect("TODO: handle error") + "TABLE".len();
149+
let idx = upper.find("TABLE")
150+
.expect("parse_create_table is only invoked when upper.starts_with(\"CREATE TABLE\") (see parse_sql_schema), so find(\"TABLE\") is always Some")
151+
+ "TABLE".len();
148152
statement[idx..paren_start].trim()
149153
};
150154

@@ -329,7 +333,7 @@ mod tests {
329333
created_at TIMESTAMP NOT NULL
330334
);
331335
"#;
332-
let schema = parse_sql_schema(ddl).expect("TODO: handle error");
336+
let schema = parse_sql_schema(ddl).unwrap();
333337
assert_eq!(schema.tables.len(), 1);
334338
assert_eq!(schema.tables[0].name, "posts");
335339
assert_eq!(schema.tables[0].columns.len(), 4);
@@ -358,7 +362,7 @@ mod tests {
358362
title TEXT NOT NULL
359363
);
360364
"#;
361-
let schema = parse_sql_schema(ddl).expect("TODO: handle error");
365+
let schema = parse_sql_schema(ddl).unwrap();
362366
assert_eq!(schema.tables.len(), 2);
363367
assert_eq!(schema.tables[0].name, "users");
364368
assert_eq!(schema.tables[1].name, "posts");
@@ -373,7 +377,7 @@ mod tests {
373377
PRIMARY KEY (post_id, tag_id)
374378
);
375379
"#;
376-
let schema = parse_sql_schema(ddl).expect("TODO: handle error");
380+
let schema = parse_sql_schema(ddl).unwrap();
377381
assert_eq!(schema.tables[0].columns.len(), 2);
378382
assert!(schema.tables[0].columns[0].is_primary_key);
379383
assert!(schema.tables[0].columns[1].is_primary_key);
@@ -382,22 +386,22 @@ mod tests {
382386
#[test]
383387
fn test_parse_if_not_exists() {
384388
let ddl = "CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT);";
385-
let schema = parse_sql_schema(ddl).expect("TODO: handle error");
389+
let schema = parse_sql_schema(ddl).unwrap();
386390
assert_eq!(schema.tables.len(), 1);
387391
assert_eq!(schema.tables[0].name, "settings");
388392
}
389393

390394
#[test]
391395
fn test_parse_empty_schema() {
392396
let ddl = "-- just a comment\n";
393-
let schema = parse_sql_schema(ddl).expect("TODO: handle error");
397+
let schema = parse_sql_schema(ddl).unwrap();
394398
assert!(schema.tables.is_empty());
395399
}
396400

397401
#[test]
398402
fn test_parse_varchar_with_length() {
399403
let ddl = "CREATE TABLE users (name VARCHAR(255) NOT NULL, email VARCHAR(320));";
400-
let schema = parse_sql_schema(ddl).expect("TODO: handle error");
404+
let schema = parse_sql_schema(ddl).unwrap();
401405
assert_eq!(schema.tables[0].columns[0].sql_type, "VARCHAR(255)");
402406
assert_eq!(schema.tables[0].columns[1].sql_type, "VARCHAR(320)");
403407
}

0 commit comments

Comments
 (0)