Skip to content

Commit 66e16fa

Browse files
hyperpolymathclaude
andcommitted
fix(jtv): sweep .expect("TODO: handle error") — 108 sites cleared
Eliminated all 108 instances of TODO-placeholder error handling: **Test code (61 sites, Policy a: .unwrap())** - number.rs: 8 test assertions → .unwrap() - wasm.rs: 17 test assertions → .unwrap() - interpreter.rs: 11 test assertions → .unwrap() - typechecker.rs: 4 test assertions → .unwrap() - formatter.rs: 9 test assertions → .unwrap() - purity.rs: 6 test assertions → .unwrap() - reversible.rs: 6 test assertions → .unwrap() **Production parser code (47 sites, Policy c: error propagation)** - parser.rs: All .next() calls on Pest parser iterators converted from .expect("TODO: handle error") to .ok_or_else() with meaningful error messages that propagate through the Result type system. - Key functions updated: parse_module, parse_import, parse_function, parse_param, parse_control_stmt, parse_reversible_stmt, parse_data_expr, parse_additive_expr, parse_term, parse_factor, parse_control_expr, parse_logical_expr, parse_logical_term, parse_logical_factor, parse_comparison_expr, parse_range_expr, parse_type_annotation. - Each error site now reports what was expected (e.g., "Expected module name", "Expected function declaration", "Expected parameter name"). Tests: 84 passed; 0 failed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a96e7f9 commit 66e16fa

8 files changed

Lines changed: 199 additions & 112 deletions

File tree

crates/jtv-core/src/formatter.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -536,52 +536,52 @@ mod tests {
536536
#[test]
537537
fn test_format_simple_assignment() {
538538
let code = "x=5+3";
539-
let formatted = format_code(code).expect("TODO: handle error");
539+
let formatted = format_code(code).unwrap();
540540
assert_eq!(formatted, "x = 5 + 3\n");
541541
}
542542

543543
#[test]
544544
fn test_format_function() {
545545
let code = "fn add(a:Int,b:Int):Int{return a+b}";
546-
let formatted = format_code(code).expect("TODO: handle error");
546+
let formatted = format_code(code).unwrap();
547547
assert!(formatted.contains("fn add(a: Int, b: Int): Int {"));
548548
assert!(formatted.contains("return a + b"));
549549
}
550550

551551
#[test]
552552
fn test_format_if_statement() {
553553
let code = "if x>0{y=1}";
554-
let formatted = format_code(code).expect("TODO: handle error");
554+
let formatted = format_code(code).unwrap();
555555
assert!(formatted.contains("if x > 0 {"));
556556
assert!(formatted.contains("y = 1"));
557557
}
558558

559559
#[test]
560560
fn test_format_pure_function() {
561561
let code = "@pure fn double(x:Int):Int{return x+x}";
562-
let formatted = format_code(code).expect("TODO: handle error");
562+
let formatted = format_code(code).unwrap();
563563
assert!(formatted.contains("@pure fn double"));
564564
}
565565

566566
#[test]
567567
fn test_format_reverse_block() {
568568
let code = "reverse{x+=5}";
569-
let formatted = format_code(code).expect("TODO: handle error");
569+
let formatted = format_code(code).unwrap();
570570
assert!(formatted.contains("reverse {"));
571571
assert!(formatted.contains("x += 5"));
572572
}
573573

574574
#[test]
575575
fn test_format_list() {
576576
let code = "nums=[1,2,3,4,5]";
577-
let formatted = format_code(code).expect("TODO: handle error");
577+
let formatted = format_code(code).unwrap();
578578
assert_eq!(formatted, "nums = [1, 2, 3, 4, 5]\n");
579579
}
580580

581581
#[test]
582582
fn test_format_for_loop() {
583583
let code = "for i in 0..10{x=x+i}";
584-
let formatted = format_code(code).expect("TODO: handle error");
584+
let formatted = format_code(code).unwrap();
585585
assert!(formatted.contains("for i in 0..10 {"));
586586
}
587587

@@ -592,14 +592,14 @@ mod tests {
592592
spaces_around_operators: false,
593593
..Default::default()
594594
};
595-
let formatted = format_code_with_config(code, config).expect("TODO: handle error");
595+
let formatted = format_code_with_config(code, config).unwrap();
596596
assert_eq!(formatted, "x=5+3\n");
597597
}
598598

599599
#[test]
600600
fn test_format_while_loop() {
601601
let code = "while x>0{x=x+-1}";
602-
let formatted = format_code(code).expect("TODO: handle error");
602+
let formatted = format_code(code).unwrap();
603603
assert!(formatted.contains("while x > 0 {"));
604604
assert!(formatted.contains("x = x + -1"));
605605
}

crates/jtv-core/src/interpreter.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,11 @@ mod tests {
548548
#[test]
549549
fn test_simple_addition() {
550550
let code = "x = 5 + 3";
551-
let program = parse_program(code).expect("TODO: handle error");
551+
let program = parse_program(code).unwrap();
552552
let mut interpreter = Interpreter::new();
553-
interpreter.run(&program).expect("TODO: handle error");
553+
interpreter.run(&program).unwrap();
554554

555-
let x = interpreter.get_variable("x").expect("TODO: handle error");
555+
let x = interpreter.get_variable("x").unwrap();
556556
assert_eq!(x, Value::Int(8));
557557
}
558558

@@ -566,11 +566,11 @@ fn add(a: Int, b: Int): Int {
566566
result = add(5, 3)
567567
"#;
568568

569-
let program = parse_program(code).expect("TODO: handle error");
569+
let program = parse_program(code).unwrap();
570570
let mut interpreter = Interpreter::new();
571-
interpreter.run(&program).expect("TODO: handle error");
571+
interpreter.run(&program).unwrap();
572572

573-
let result = interpreter.get_variable("result").expect("TODO: handle error");
573+
let result = interpreter.get_variable("result").unwrap();
574574
assert_eq!(result, Value::Int(8));
575575
}
576576

@@ -583,10 +583,10 @@ fn double(x: Int): Int {
583583
}
584584
"#;
585585

586-
let program = parse_program(code).expect("TODO: handle error");
586+
let program = parse_program(code).unwrap();
587587
let mut interpreter = Interpreter::new();
588588
// Just test that it parses and runs without calling
589-
interpreter.run(&program).expect("TODO: handle error");
589+
interpreter.run(&program).unwrap();
590590
}
591591

592592
#[test]
@@ -598,11 +598,11 @@ fn double(x: Int): Int {
598598
}
599599
"#;
600600

601-
let program = parse_program(code).expect("TODO: handle error");
601+
let program = parse_program(code).unwrap();
602602
let mut interpreter = Interpreter::new();
603-
interpreter.run(&program).expect("TODO: handle error");
603+
interpreter.run(&program).unwrap();
604604

605-
let sum = interpreter.get_variable("sum").expect("TODO: handle error");
605+
let sum = interpreter.get_variable("sum").unwrap();
606606
assert_eq!(sum, Value::Int(15)); // 1+2+3+4+5
607607
}
608608
}

crates/jtv-core/src/number.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,63 +274,63 @@ mod tests {
274274
fn test_int_addition() {
275275
let a = Value::Int(5);
276276
let b = Value::Int(3);
277-
let result = a.add(&b).expect("TODO: handle error");
277+
let result = a.add(&b).unwrap();
278278
assert_eq!(result, Value::Int(8));
279279
}
280280

281281
#[test]
282282
fn test_float_addition() {
283283
let a = Value::Float(5.5);
284284
let b = Value::Float(3.2);
285-
let result = a.add(&b).expect("TODO: handle error");
285+
let result = a.add(&b).unwrap();
286286
assert!(matches!(result, Value::Float(_)));
287287
}
288288

289289
#[test]
290290
fn test_rational_addition() {
291291
let a = Value::Rational(Ratio::new(1, 2));
292292
let b = Value::Rational(Ratio::new(1, 3));
293-
let result = a.add(&b).expect("TODO: handle error");
293+
let result = a.add(&b).unwrap();
294294
assert_eq!(result, Value::Rational(Ratio::new(5, 6)));
295295
}
296296

297297
#[test]
298298
fn test_complex_addition() {
299299
let a = Value::Complex(Complex64::new(1.0, 2.0));
300300
let b = Value::Complex(Complex64::new(3.0, 4.0));
301-
let result = a.add(&b).expect("TODO: handle error");
301+
let result = a.add(&b).unwrap();
302302
assert_eq!(result, Value::Complex(Complex64::new(4.0, 6.0)));
303303
}
304304

305305
#[test]
306306
fn test_hex_addition() {
307307
let a = Value::Hex(0x10);
308308
let b = Value::Hex(0x20);
309-
let result = a.add(&b).expect("TODO: handle error");
309+
let result = a.add(&b).unwrap();
310310
assert_eq!(result, Value::Hex(0x30));
311311
}
312312

313313
#[test]
314314
fn test_binary_addition() {
315315
let a = Value::Binary(0b1010);
316316
let b = Value::Binary(0b0101);
317-
let result = a.add(&b).expect("TODO: handle error");
317+
let result = a.add(&b).unwrap();
318318
assert_eq!(result, Value::Binary(0b1111));
319319
}
320320

321321
#[test]
322322
fn test_symbolic_addition() {
323323
let a = Value::Symbolic("x".to_string());
324324
let b = Value::Symbolic("y".to_string());
325-
let result = a.add(&b).expect("TODO: handle error");
325+
let result = a.add(&b).unwrap();
326326
assert_eq!(result, Value::Symbolic("x + y".to_string()));
327327
}
328328

329329
#[test]
330330
fn test_type_coercion() {
331331
let a = Value::Int(5);
332332
let b = Value::Float(3.5);
333-
let result = a.add(&b).expect("TODO: handle error");
333+
let result = a.add(&b).unwrap();
334334
assert!(matches!(result, Value::Float(_)));
335335
}
336336
}

0 commit comments

Comments
 (0)