diff --git a/src/ephapax-desugar/src/lib.rs b/src/ephapax-desugar/src/lib.rs index 2629e48d..415d0924 100644 --- a/src/ephapax-desugar/src/lib.rs +++ b/src/ephapax-desugar/src/lib.rs @@ -602,11 +602,11 @@ impl Desugarer { // Get the full sum type for the "other side" annotations let empty_subst: HashMap<&SmolStr, &SurfaceTy> = HashMap::new(); - let (_, ctors) = self + let (_, ctor_defs) = self .registry .get_type_ctors(info.data_name.as_str()) - .expect("TODO: handle error"); - let ctors = ctors.clone(); + .ok_or_else(|| DesugarError::UnknownType { name: info.data_name.to_string() })?; + let ctors = ctor_defs.clone(); // Wrap in inl/inr chain based on index self.wrap_injection(payload, info.index, &ctors, &empty_subst, span) @@ -712,8 +712,9 @@ impl Desugarer { // Find the data type from constructor patterns let data_name = self.find_data_type_from_arms(arms)?; - let (_, ctors) = self.registry.get_type_ctors(data_name.as_str()).expect("TODO: handle error"); - let ctors = ctors.clone(); + let (_, ctor_defs) = self.registry.get_type_ctors(data_name.as_str()) + .ok_or_else(|| DesugarError::UnknownType { name: data_name.to_string() })?; + let ctors = ctor_defs.clone(); // Build an ordered map: constructor index → (pattern bindings, body) let mut arm_map: HashMap = HashMap::new(); @@ -1081,7 +1082,7 @@ mod tests { args: vec![SurfaceTy::Base(BaseTy::I32)], }; - let core = ds.desugar_ty(&ty).expect("TODO: handle error"); + let core = ds.desugar_ty(&ty).unwrap(); // Option(I32) = () + I32 assert_eq!( core, @@ -1102,7 +1103,7 @@ mod tests { args: vec![], }; - let core = ds.desugar_ty(&ty).expect("TODO: handle error"); + let core = ds.desugar_ty(&ty).unwrap(); // Color = () + (() + ()) assert_eq!( core, @@ -1141,7 +1142,7 @@ mod tests { args: vec![], }); - let core = ds.desugar_expr(&expr).expect("TODO: handle error"); + let core = ds.desugar_expr(&expr).unwrap(); // None → inl(()) assert!(matches!(core.kind, ExprKind::Inl { .. })); } @@ -1156,7 +1157,7 @@ mod tests { args: vec![se(SurfaceExprKind::Lit(Literal::I32(42)))], }); - let core = ds.desugar_expr(&expr).expect("TODO: handle error"); + let core = ds.desugar_expr(&expr).unwrap(); // Some(42) → inr(42) assert!(matches!(core.kind, ExprKind::Inr { .. })); } @@ -1171,7 +1172,7 @@ mod tests { args: vec![], }); - let core = ds.desugar_expr(&expr).expect("TODO: handle error"); + let core = ds.desugar_expr(&expr).unwrap(); // Green → inr(inl(())) if let ExprKind::Inr { value, .. } = &core.kind { assert!(matches!(value.kind, ExprKind::Inl { .. })); @@ -1190,7 +1191,7 @@ mod tests { args: vec![], }); - let core = ds.desugar_expr(&expr).expect("TODO: handle error"); + let core = ds.desugar_expr(&expr).unwrap(); // Blue → inr(inr(())) if let ExprKind::Inr { value, .. } = &core.kind { if let ExprKind::Inr { .. } = &value.kind { @@ -1254,7 +1255,7 @@ mod tests { ], }); - let core = ds.desugar_expr(&expr).expect("TODO: handle error"); + let core = ds.desugar_expr(&expr).unwrap(); // Should produce a case expression assert!(matches!(core.kind, ExprKind::Case { .. })); } @@ -1294,7 +1295,7 @@ mod tests { ], }); - let core = ds.desugar_expr(&expr).expect("TODO: handle error"); + let core = ds.desugar_expr(&expr).unwrap(); // Should produce nested case: case c of inl _ => 1 | inr rest => case rest of ... if let ExprKind::Case { right_body, .. } = &core.kind { assert!( @@ -1330,7 +1331,7 @@ mod tests { ], }); - let core = ds.desugar_expr(&expr).expect("TODO: handle error"); + let core = ds.desugar_expr(&expr).unwrap(); // Wildcard should fill in the missing Green and Blue arms assert!(matches!(core.kind, ExprKind::Case { .. })); } @@ -1407,7 +1408,7 @@ mod tests { ], }; - let core = desugar(&module).expect("TODO: handle error"); + let core = desugar(&module).unwrap(); // Data declaration should not appear in core assert_eq!( core.decls.len(), @@ -1486,7 +1487,7 @@ mod tests { ], }; - let core = desugar(&module).expect("TODO: handle error"); + let core = desugar(&module).unwrap(); assert_eq!(core.decls.len(), 1); let result = type_check_module(&core); @@ -1549,7 +1550,7 @@ mod tests { ], }; - let core = desugar(&module).expect("TODO: handle error"); + let core = desugar(&module).unwrap(); // Print desugared core for debugging assert_eq!(core.decls.len(), 1); diff --git a/src/ephapax-package/src/lib.rs b/src/ephapax-package/src/lib.rs index 4e28fe23..ff7035a0 100644 --- a/src/ephapax-package/src/lib.rs +++ b/src/ephapax-package/src/lib.rs @@ -107,21 +107,21 @@ mod tests { #[test] fn test_init_project() { - let temp = TempDir::new().expect("TODO: handle error"); - init_project(temp.path(), "test-project").expect("TODO: handle error"); + let temp = TempDir::new().unwrap(); + init_project(temp.path(), "test-project").unwrap(); assert!(temp.path().join("ephapax.toml").exists()); assert!(temp.path().join("src").exists()); assert!(temp.path().join("src/main.eph").exists()); - let manifest = Manifest::from_file(&temp.path().join("ephapax.toml")).expect("TODO: handle error"); + let manifest = Manifest::from_file(&temp.path().join("ephapax.toml")).unwrap(); assert_eq!(manifest.package.name, "test-project"); } #[test] fn test_init_project_already_exists() { - let temp = TempDir::new().expect("TODO: handle error"); - std::fs::write(temp.path().join("ephapax.toml"), "").expect("TODO: handle error"); + let temp = TempDir::new().unwrap(); + std::fs::write(temp.path().join("ephapax.toml"), "").unwrap(); let result = init_project(temp.path(), "test"); assert!(result.is_err()); diff --git a/src/ephapax-package/src/manifest.rs b/src/ephapax-package/src/manifest.rs index 7fd22423..debd7822 100644 --- a/src/ephapax-package/src/manifest.rs +++ b/src/ephapax-package/src/manifest.rs @@ -195,7 +195,8 @@ fn is_valid_package_name(name: &str) -> bool { } // Must start with letter - if !name.chars().next().expect("TODO: handle error").is_ascii_lowercase() { + // invariant: we already checked !is_empty(), so chars().next() cannot fail + if !name.chars().next().expect("invariant: name is not empty").is_ascii_lowercase() { return false; } @@ -221,7 +222,7 @@ license = "PMPL-1.0-or-later" linear-collections = "1.0" "#; - let manifest = Manifest::parse(toml).expect("TODO: handle error"); + let manifest = Manifest::parse(toml).unwrap(); assert_eq!(manifest.package.name, "my-lib"); assert_eq!(manifest.package.version, "0.1.0"); assert_eq!(manifest.dependencies.len(), 1); @@ -242,7 +243,7 @@ local-lib = { path = "../local" } git-lib = { git = "https://github.com/example/lib", tag = "v1.0" } "#; - let manifest = Manifest::parse(toml).expect("TODO: handle error"); + let manifest = Manifest::parse(toml).unwrap(); assert_eq!(manifest.dependencies.len(), 3); let affine = &manifest.dependencies["affine-utils"]; diff --git a/src/ephapax-package/src/registry.rs b/src/ephapax-package/src/registry.rs index 22613308..a09f8a65 100644 --- a/src/ephapax-package/src/registry.rs +++ b/src/ephapax-package/src/registry.rs @@ -273,8 +273,8 @@ mod tests { #[test] fn test_registry_creation() { - let temp = TempDir::new().expect("TODO: handle error"); - let registry = Registry::open_at(temp.path().to_path_buf()).expect("TODO: handle error"); + let temp = TempDir::new().unwrap(); + let registry = Registry::open_at(temp.path().to_path_buf()).unwrap(); assert!(temp.path().join("packages").exists()); assert!(temp.path().join("cache").exists()); @@ -283,15 +283,15 @@ mod tests { #[test] fn test_package_installation() { - let temp = TempDir::new().expect("TODO: handle error"); - let mut registry = Registry::open_at(temp.path().to_path_buf()).expect("TODO: handle error"); + let temp = TempDir::new().unwrap(); + let mut registry = Registry::open_at(temp.path().to_path_buf()).unwrap(); - let source = TempDir::new().expect("TODO: handle error"); - std::fs::write(source.path().join("test.eph"), "fn main(): I32 = 42").expect("TODO: handle error"); + let source = TempDir::new().unwrap(); + std::fs::write(source.path().join("test.eph"), "fn main(): I32 = 42").unwrap(); registry .install_package("test-lib", "1.0.0", source.path()) - .expect("TODO: handle error"); + .unwrap(); assert!(registry.has_package("test-lib", "1.0.0")); let versions = registry.get_versions("test-lib"); @@ -300,16 +300,16 @@ mod tests { #[test] fn test_package_search() { - let temp = TempDir::new().expect("TODO: handle error"); - let mut registry = Registry::open_at(temp.path().to_path_buf()).expect("TODO: handle error"); + let temp = TempDir::new().unwrap(); + let mut registry = Registry::open_at(temp.path().to_path_buf()).unwrap(); - let source = TempDir::new().expect("TODO: handle error"); + let source = TempDir::new().unwrap(); registry .install_package("linear-collections", "1.0.0", source.path()) - .expect("TODO: handle error"); + .unwrap(); registry .install_package("affine-utils", "0.5.0", source.path()) - .expect("TODO: handle error"); + .unwrap(); let results = registry.search("linear"); assert_eq!(results, vec!["linear-collections"]); diff --git a/src/ephapax-package/src/resolver.rs b/src/ephapax-package/src/resolver.rs index 59b51975..d686b774 100644 --- a/src/ephapax-package/src/resolver.rs +++ b/src/ephapax-package/src/resolver.rs @@ -267,22 +267,22 @@ mod tests { #[test] fn test_simple_resolution() { - let temp = TempDir::new().expect("TODO: handle error"); - let mut registry = Registry::open_at(temp.path().to_path_buf()).expect("TODO: handle error"); + let temp = TempDir::new().unwrap(); + let mut registry = Registry::open_at(temp.path().to_path_buf()).unwrap(); // Create package structure let pkg_dir = temp.path().join("pkg"); - std::fs::create_dir_all(&pkg_dir).expect("TODO: handle error"); + std::fs::create_dir_all(&pkg_dir).unwrap(); let dep_manifest = create_test_package("dep", "1.0.0", vec![]); - dep_manifest.to_file(&pkg_dir.join("ephapax.toml")).expect("TODO: handle error"); - registry.install_package("dep", "1.0.0", &pkg_dir).expect("TODO: handle error"); + dep_manifest.to_file(&pkg_dir.join("ephapax.toml")).unwrap(); + registry.install_package("dep", "1.0.0", &pkg_dir).unwrap(); // Main package depends on dep let main_manifest = create_test_package("main", "1.0.0", vec![("dep", "^1.0")]); let resolver = Resolver::new(®istry); - let resolved = resolver.resolve(&main_manifest).expect("TODO: handle error"); + let resolved = resolver.resolve(&main_manifest).unwrap(); assert_eq!(resolved.packages.len(), 1); assert!(resolved.packages.contains_key("dep")); @@ -290,29 +290,29 @@ mod tests { #[test] fn test_transitive_resolution() { - let temp = TempDir::new().expect("TODO: handle error"); - let mut registry = Registry::open_at(temp.path().to_path_buf()).expect("TODO: handle error"); + let temp = TempDir::new().unwrap(); + let mut registry = Registry::open_at(temp.path().to_path_buf()).unwrap(); let pkg_dir = temp.path().join("pkg"); - std::fs::create_dir_all(&pkg_dir).expect("TODO: handle error"); + std::fs::create_dir_all(&pkg_dir).unwrap(); // leaf: no dependencies let leaf = create_test_package("leaf", "1.0.0", vec![]); - leaf.to_file(&pkg_dir.join("ephapax.toml")).expect("TODO: handle error"); - registry.install_package("leaf", "1.0.0", &pkg_dir).expect("TODO: handle error"); + leaf.to_file(&pkg_dir.join("ephapax.toml")).unwrap(); + registry.install_package("leaf", "1.0.0", &pkg_dir).unwrap(); // middle: depends on leaf let middle = create_test_package("middle", "1.0.0", vec![("leaf", "^1.0")]); - middle.to_file(&pkg_dir.join("ephapax.toml")).expect("TODO: handle error"); + middle.to_file(&pkg_dir.join("ephapax.toml")).unwrap(); registry .install_package("middle", "1.0.0", &pkg_dir) - .expect("TODO: handle error"); + .unwrap(); // main: depends on middle let main = create_test_package("main", "1.0.0", vec![("middle", "^1.0")]); let resolver = Resolver::new(®istry); - let resolved = resolver.resolve(&main).expect("TODO: handle error"); + let resolved = resolver.resolve(&main).unwrap(); assert_eq!(resolved.packages.len(), 2); assert!(resolved.packages.contains_key("middle")); @@ -320,30 +320,30 @@ mod tests { // Check topological order (leaf before middle) let order = resolved.topological_order(); - let leaf_pos = order.iter().position(|n| n == "leaf").expect("TODO: handle error"); - let middle_pos = order.iter().position(|n| n == "middle").expect("TODO: handle error"); + let leaf_pos = order.iter().position(|n| n == "leaf").unwrap(); + let middle_pos = order.iter().position(|n| n == "middle").unwrap(); assert!(leaf_pos < middle_pos); } #[test] fn test_version_selection() { - let temp = TempDir::new().expect("TODO: handle error"); - let mut registry = Registry::open_at(temp.path().to_path_buf()).expect("TODO: handle error"); + let temp = TempDir::new().unwrap(); + let mut registry = Registry::open_at(temp.path().to_path_buf()).unwrap(); let pkg_dir = temp.path().join("pkg"); - std::fs::create_dir_all(&pkg_dir).expect("TODO: handle error"); + std::fs::create_dir_all(&pkg_dir).unwrap(); // Install multiple versions for version in &["1.0.0", "1.1.0", "1.2.0", "2.0.0"] { let pkg = create_test_package("lib", version, vec![]); - pkg.to_file(&pkg_dir.join("ephapax.toml")).expect("TODO: handle error"); - registry.install_package("lib", version, &pkg_dir).expect("TODO: handle error"); + pkg.to_file(&pkg_dir.join("ephapax.toml")).unwrap(); + registry.install_package("lib", version, &pkg_dir).unwrap(); } let main = create_test_package("main", "1.0.0", vec![("lib", "^1.0")]); let resolver = Resolver::new(®istry); - let resolved = resolver.resolve(&main).expect("TODO: handle error"); + let resolved = resolver.resolve(&main).unwrap(); // Should pick 1.2.0 (latest matching ^1.0) let lib = &resolved.packages["lib"]; diff --git a/src/ephapax-parser/src/lib.rs b/src/ephapax-parser/src/lib.rs index 3d4fe148..7d3437cd 100644 --- a/src/ephapax-parser/src/lib.rs +++ b/src/ephapax-parser/src/lib.rs @@ -578,10 +578,12 @@ fn parse_seq_expr_core(pair: pest::iterators::Pair) -> Result { assert_eq!(clauses.len(), 2); assert!(clauses[0].op.is_empty()); // return diff --git a/src/ephapax-parser/src/lists_tuples.rs b/src/ephapax-parser/src/lists_tuples.rs index ba9fa878..2aca56c8 100644 --- a/src/ephapax-parser/src/lists_tuples.rs +++ b/src/ephapax-parser/src/lists_tuples.rs @@ -209,7 +209,7 @@ mod tests { #[test] fn test_parse_empty_list() { - let expr = parse_expr_helper("[]").expect("TODO: handle error"); + let expr = parse_expr_helper("[]").unwrap(); match expr.kind { ExprKind::ListLit(elements) => assert_eq!(elements.len(), 0), other => panic!("Expected ListLit, got {other:?}"), @@ -218,7 +218,7 @@ mod tests { #[test] fn test_parse_list_literal() { - let expr = parse_expr_helper("[1, 2, 3]").expect("TODO: handle error"); + let expr = parse_expr_helper("[1, 2, 3]").unwrap(); match expr.kind { ExprKind::ListLit(elements) => assert_eq!(elements.len(), 3), other => panic!("Expected ListLit, got {other:?}"), @@ -227,7 +227,7 @@ mod tests { #[test] fn test_parse_tuple_literal() { - let expr = parse_expr_helper("(1, 2, 3)").expect("TODO: handle error"); + let expr = parse_expr_helper("(1, 2, 3)").unwrap(); match expr.kind { ExprKind::TupleLit(elements) => assert_eq!(elements.len(), 3), other => panic!("Expected TupleLit, got {other:?}"), @@ -236,7 +236,7 @@ mod tests { #[test] fn test_parse_unit() { - let expr = parse_expr_helper("()").expect("TODO: handle error"); + let expr = parse_expr_helper("()").unwrap(); match expr.kind { ExprKind::Lit(ephapax_syntax::Literal::Unit) => {} other => panic!("Expected Unit literal, got {other:?}"), @@ -245,7 +245,7 @@ mod tests { #[test] fn test_parse_list_index() { - let expr = parse_expr_helper("list[0]").expect("TODO: handle error"); + let expr = parse_expr_helper("list[0]").unwrap(); match expr.kind { ExprKind::ListIndex { .. } => {} other => panic!("Expected ListIndex, got {other:?}"), @@ -254,7 +254,7 @@ mod tests { #[test] fn test_parse_tuple_index() { - let expr = parse_expr_helper("tuple.0").expect("TODO: handle error"); + let expr = parse_expr_helper("tuple.0").unwrap(); match expr.kind { ExprKind::TupleIndex { index, .. } => assert_eq!(index, 0), other => panic!("Expected TupleIndex, got {other:?}"), diff --git a/src/ephapax-parser/src/surface.rs b/src/ephapax-parser/src/surface.rs index 6820ef40..bcc9a4db 100644 --- a/src/ephapax-parser/src/surface.rs +++ b/src/ephapax-parser/src/surface.rs @@ -302,12 +302,14 @@ fn parse_seq_expr(pair: pest::iterators::Pair) -> Result) -> Result= 2 { - let body = parse_expression(exprs.pop().expect("TODO: handle error"))?; - let guard_expr = parse_expression(exprs.pop().expect("TODO: handle error"))?; + // invariant: len() >= 2 guarantees pop() returns Some twice + let body = parse_expression(exprs.pop().expect("invariant: exprs.len() >= 2"))?; + let guard_expr = parse_expression(exprs.pop().expect("invariant: exprs.len() >= 2"))?; (Some(Box::new(guard_expr)), body) } else if exprs.len() == 1 { - (None, parse_expression(exprs.pop().expect("TODO: handle error"))?) + // invariant: len() == 1 guarantees pop() returns Some + (None, parse_expression(exprs.pop().expect("invariant: exprs.len() == 1"))?) } else { return Err(ParseError::missing("match arm body")); }; @@ -1171,11 +1175,15 @@ fn parse_atom_expr(pair: pest::iterators::Pair) -> Result Ok(SurfaceExpr::new(SurfaceExprKind::Lit(Literal::Unit), span)), - 1 => Ok(exprs.into_iter().next().expect("TODO: handle error")), + 1 => { + // invariant: match arm 1 guarantees len() == 1, so next() returns Some + Ok(exprs.into_iter().next().expect("invariant: exprs.len() == 1")) + } 2 => { let mut iter = exprs.into_iter(); - let left = iter.next().expect("TODO: handle error"); - let right = iter.next().expect("TODO: handle error"); + // invariant: match arm 2 guarantees len() == 2, so next() returns Some twice + let left = iter.next().expect("invariant: exprs.len() == 2"); + let right = iter.next().expect("invariant: exprs.len() == 2"); Ok(SurfaceExpr::new( SurfaceExprKind::Pair { left: Box::new(left), @@ -1470,7 +1478,7 @@ mod tests { #[test] fn parse_data_declaration() { let source = "data Option(a) = None | Some(a)"; - let module = parse_surface_module(source, "test").expect("TODO: handle error"); + let module = parse_surface_module(source, "test").unwrap(); assert_eq!(module.decls.len(), 1); if let SurfaceDecl::Data(d) = &module.decls[0] { assert_eq!(d.name.as_str(), "Option"); @@ -1486,7 +1494,7 @@ mod tests { #[test] fn parse_data_no_params() { let source = "data Color = Red | Green | Blue"; - let module = parse_surface_module(source, "test").expect("TODO: handle error"); + let module = parse_surface_module(source, "test").unwrap(); if let SurfaceDecl::Data(d) = &module.decls[0] { assert_eq!(d.name.as_str(), "Color"); assert!(d.params.is_empty()); @@ -1499,14 +1507,14 @@ mod tests { #[test] fn parse_construct_nullary() { let source = "None"; - let expr = parse_surface_expr(source).expect("TODO: handle error"); + let expr = parse_surface_expr(source).unwrap(); assert!(matches!(expr.kind, SurfaceExprKind::Construct { .. })); } #[test] fn parse_construct_with_arg() { let source = "Some(42)"; - let expr = parse_surface_expr(source).expect("TODO: handle error"); + let expr = parse_surface_expr(source).unwrap(); if let SurfaceExprKind::Construct { ctor, args } = &expr.kind { assert_eq!(ctor.as_str(), "Some"); assert_eq!(args.len(), 1); @@ -1521,7 +1529,7 @@ mod tests { | None => 0 | Some(v) => v end"#; - let expr = parse_surface_expr(source).expect("TODO: handle error"); + let expr = parse_surface_expr(source).unwrap(); if let SurfaceExprKind::Match { arms, .. } = &expr.kind { assert_eq!(arms.len(), 2); } else { @@ -1537,14 +1545,14 @@ mod tests { end"#; // Need Color data type registered for Red to parse as constructor // But Red is an uppercase identifier, so it parses as construct_expr - let expr = parse_surface_expr(source).expect("TODO: handle error"); + let expr = parse_surface_expr(source).unwrap(); assert!(matches!(expr.kind, SurfaceExprKind::Match { .. })); } #[test] fn parse_named_type() { let source = "fn unwrap(x: Option(I32)): I32 = x"; - let module = parse_surface_module(source, "test").expect("TODO: handle error"); + let module = parse_surface_module(source, "test").unwrap(); if let SurfaceDecl::Fn { params, .. } = &module.decls[0] { assert!(matches!(¶ms[0].1, SurfaceTy::Named { .. })); } @@ -1553,14 +1561,14 @@ mod tests { #[test] fn parse_existing_let_expr() { let source = "let x = 42 in x"; - let expr = parse_surface_expr(source).expect("TODO: handle error"); + let expr = parse_surface_expr(source).unwrap(); assert!(matches!(expr.kind, SurfaceExprKind::Let { .. })); } #[test] fn parse_existing_let_lin_expr() { let source = "let! x = 42 in x"; - let expr = parse_surface_expr(source).expect("TODO: handle error"); + let expr = parse_surface_expr(source).unwrap(); assert!(matches!(expr.kind, SurfaceExprKind::LetLin { .. })); } @@ -1575,7 +1583,7 @@ mod tests { | Some(v) => v end "#; - let module = parse_surface_module(source, "test").expect("TODO: handle error"); + let module = parse_surface_module(source, "test").unwrap(); assert_eq!(module.decls.len(), 2); assert!(matches!(&module.decls[0], SurfaceDecl::Data(_))); assert!(matches!(&module.decls[1], SurfaceDecl::Fn { .. })); @@ -1592,10 +1600,10 @@ fn test(opt: Option(I32)): I32 = | Some(v) => v end "#; - let surface = parse_surface_module(source, "test").expect("TODO: handle error"); + let surface = parse_surface_module(source, "test").unwrap(); assert_eq!(surface.decls.len(), 2); - let core = ephapax_desugar::desugar(&surface).expect("TODO: handle error"); + let core = ephapax_desugar::desugar(&surface).unwrap(); assert_eq!(core.decls.len(), 1); // data consumed, only fn remains let result = ephapax_typing::type_check_module(&core); diff --git a/src/ephapax-typing/src/lib.rs b/src/ephapax-typing/src/lib.rs index e4097eea..f17cb8a5 100644 --- a/src/ephapax-typing/src/lib.rs +++ b/src/ephapax-typing/src/lib.rs @@ -1554,7 +1554,7 @@ mod tests { fn test_literal_typing() { let mut tc = TypeChecker::new(); let expr = dummy_expr(ExprKind::Lit(Literal::I32(42))); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::I32)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::I32)); } #[test] @@ -1723,7 +1723,7 @@ mod tests { value: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(42)))), body: Box::new(dummy_expr(ExprKind::Var("x".into()))), }); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::I32)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::I32)); } #[test] @@ -1749,7 +1749,7 @@ mod tests { right: Box::new(dummy_expr(ExprKind::Lit(Literal::Bool(true)))), }); assert_eq!( - tc.check(&expr).expect("TODO: handle error"), + tc.check(&expr).unwrap(), Ty::Prod { left: Box::new(Ty::Base(BaseTy::I32)), right: Box::new(Ty::Base(BaseTy::Bool)), @@ -1764,7 +1764,7 @@ mod tests { left: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(1)))), right: Box::new(dummy_expr(ExprKind::Lit(Literal::Bool(true)))), })))); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::I32)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::I32)); } #[test] @@ -1792,7 +1792,7 @@ mod tests { value: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(42)))), }); assert_eq!( - tc.check(&expr).expect("TODO: handle error"), + tc.check(&expr).unwrap(), Ty::Sum { left: Box::new(Ty::Base(BaseTy::I32)), right: Box::new(Ty::Base(BaseTy::Bool)), @@ -1813,7 +1813,7 @@ mod tests { right_var: "y".into(), right_body: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(0)))), }); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::I32)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::I32)); } #[test] @@ -1877,7 +1877,7 @@ mod tests { body: Box::new(dummy_expr(ExprKind::Var("x".into()))), }); assert_eq!( - tc.check(&expr).expect("TODO: handle error"), + tc.check(&expr).unwrap(), Ty::Fun { param: Box::new(Ty::Base(BaseTy::I32)), ret: Box::new(Ty::Base(BaseTy::I32)), @@ -1896,7 +1896,7 @@ mod tests { })), arg: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(42)))), }); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::I32)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::I32)); } #[test] @@ -1923,7 +1923,7 @@ mod tests { Literal::I32(42), ))))); assert_eq!( - tc.check(&expr).expect("TODO: handle error"), + tc.check(&expr).unwrap(), Ty::Prod { left: Box::new(Ty::Base(BaseTy::I32)), right: Box::new(Ty::Base(BaseTy::I32)), @@ -1957,7 +1957,7 @@ mod tests { let expr = dummy_expr(ExprKind::Drop(Box::new(dummy_expr(ExprKind::Var( "s".into(), ))))); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::Unit)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::Unit)); } #[test] @@ -2156,7 +2156,7 @@ mod tests { left: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(1)))), right: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(2)))), }); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::I32)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::I32)); } #[test] @@ -2167,7 +2167,7 @@ mod tests { left: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(1)))), right: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(2)))), }); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::Bool)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::Bool)); } #[test] @@ -2177,7 +2177,7 @@ mod tests { op: UnaryOp::Neg, operand: Box::new(dummy_expr(ExprKind::Lit(Literal::I32(42)))), }); - assert_eq!(tc.check(&expr).expect("TODO: handle error"), Ty::Base(BaseTy::I32)); + assert_eq!(tc.check(&expr).unwrap(), Ty::Base(BaseTy::I32)); } #[test] @@ -2504,10 +2504,10 @@ mod tests { let mut registry = ModuleRegistry::new(); // Type check lib first - type_check_module_with_registry(&lib_module, &mut registry).expect("TODO: handle error"); + type_check_module_with_registry(&lib_module, &mut registry).unwrap(); // Type check main — imports double from lib - type_check_module_with_registry(&main_module, &mut registry).expect("TODO: handle error"); + type_check_module_with_registry(&main_module, &mut registry).unwrap(); } #[test] @@ -2546,7 +2546,7 @@ mod tests { }; let mut registry = ModuleRegistry::new(); - type_check_module_with_registry(&lib_module, &mut registry).expect("TODO: handle error"); + type_check_module_with_registry(&lib_module, &mut registry).unwrap(); // Should fail — "secret" is private assert!(type_check_module_with_registry(&main_module, &mut registry).is_err()); } @@ -2590,7 +2590,7 @@ mod tests { }; let mut registry = ModuleRegistry::new(); - type_check_module_with_registry(&lib_module, &mut registry).expect("TODO: handle error"); - type_check_module_with_registry(&main_module, &mut registry).expect("TODO: handle error"); + type_check_module_with_registry(&lib_module, &mut registry).unwrap(); + type_check_module_with_registry(&main_module, &mut registry).unwrap(); } } diff --git a/src/ephapax-vram-cache/src/lib.rs b/src/ephapax-vram-cache/src/lib.rs index 53d1770c..1a4ccd7c 100644 --- a/src/ephapax-vram-cache/src/lib.rs +++ b/src/ephapax-vram-cache/src/lib.rs @@ -323,12 +323,12 @@ mod tests { #[test] #[cfg(feature = "cpu-fallback")] fn test_basic_cache_operations() { - let mut cache = VramCache::new(1024 * 1024).expect("TODO: handle error"); // 1MB cache + let mut cache = VramCache::new(1024 * 1024).unwrap(); // 1MB cache let test_data = b"test IR data"; - cache.insert("test.eph", test_data).expect("TODO: handle error"); + cache.insert("test.eph", test_data).unwrap(); - let retrieved = cache.get("test.eph").expect("TODO: handle error"); + let retrieved = cache.get("test.eph").unwrap(); assert_eq!(retrieved, Some(test_data.to_vec())); assert_eq!(cache.stats().hits, 1); @@ -338,9 +338,9 @@ mod tests { #[test] #[cfg(feature = "cpu-fallback")] fn test_cache_miss() { - let mut cache = VramCache::new(1024 * 1024).expect("TODO: handle error"); + let mut cache = VramCache::new(1024 * 1024).unwrap(); - let result = cache.get("nonexistent.eph").expect("TODO: handle error"); + let result = cache.get("nonexistent.eph").unwrap(); assert_eq!(result, None); assert_eq!(cache.stats().misses, 1); } @@ -348,17 +348,17 @@ mod tests { #[test] #[cfg(feature = "cpu-fallback")] fn test_lru_eviction() { - let mut cache = VramCache::new(100).expect("TODO: handle error"); // Very small cache + let mut cache = VramCache::new(100).unwrap(); // Very small cache - cache.insert("file1.eph", b"data1").expect("TODO: handle error"); + cache.insert("file1.eph", b"data1").unwrap(); std::thread::sleep(std::time::Duration::from_millis(10)); - cache.insert("file2.eph", b"data2").expect("TODO: handle error"); + cache.insert("file2.eph", b"data2").unwrap(); // Insert large data that triggers eviction - cache.insert("file3.eph", &vec![0u8; 90]).expect("TODO: handle error"); + cache.insert("file3.eph", &vec![0u8; 90]).unwrap(); // file1 should be evicted (LRU) - assert_eq!(cache.get("file1.eph").expect("TODO: handle error"), None); + assert_eq!(cache.get("file1.eph").unwrap(), None); assert!(cache.stats().evictions > 0); } } diff --git a/src/ephapax-wasm/src/debug.rs b/src/ephapax-wasm/src/debug.rs index c28fc3f2..5e0afaad 100644 --- a/src/ephapax-wasm/src/debug.rs +++ b/src/ephapax-wasm/src/debug.rs @@ -163,7 +163,7 @@ mod tests { let metadata = generate_mode_metadata(&debug_info); assert!(!metadata.is_empty()); - let decoded: serde_json::Value = serde_json::from_slice(&metadata).expect("TODO: handle error"); + let decoded: serde_json::Value = serde_json::from_slice(&metadata).unwrap(); assert_eq!(decoded["mode"], "affine"); assert_eq!(decoded["variables"][0]["name"], "x"); } diff --git a/tools/ephapax-dap/src/main.rs b/tools/ephapax-dap/src/main.rs index 04c7fb29..41ac6858 100644 --- a/tools/ephapax-dap/src/main.rs +++ b/tools/ephapax-dap/src/main.rs @@ -193,12 +193,11 @@ fn main() -> io::Result<()> { // DAP uses Content-Length headers like LSP if line.starts_with("Content-Length:") { - let len: usize = line - .strip_prefix("Content-Length:") - .expect("TODO: handle error") - .trim() - .parse() - .unwrap_or(0); + let len_str = match line.strip_prefix("Content-Length:") { + Some(s) => s.trim(), + None => continue, // should not happen if startswith check passed, but be safe + }; + let len: usize = len_str.parse().unwrap_or(0); // Read empty line let mut empty = String::new(); @@ -210,7 +209,10 @@ fn main() -> io::Result<()> { if let Ok(msg) = serde_json::from_slice::(&body) { let response = debugger.handle_request(&msg); - let response_json = serde_json::to_string(&response).expect("TODO: handle error"); + let response_json = match serde_json::to_string(&response) { + Ok(json) => json, + Err(_) => continue, // skip if JSON serialization fails + }; let header = format!("Content-Length: {}\r\n\r\n", response_json.len()); let mut out = stdout.lock();