diff --git a/src/classes/shopping_cart.ts b/src/classes/shopping_cart.ts index 301e2755..d84993ff 100644 --- a/src/classes/shopping_cart.ts +++ b/src/classes/shopping_cart.ts @@ -178,9 +178,10 @@ export class ShoppingCart { this.cart.push(...optimumMatch); this.match.push({ ingredient, selection: optimumMatch }); } catch (error) { - /* v8 ignore else -- @preserve */ if (error instanceof NoProductMatchError) { this.misMatch.push({ ingredient, reason: error.reason }); + } else { + throw error; } } } diff --git a/src/utils/parser_helpers.ts b/src/utils/parser_helpers.ts index 138ec279..263f5167 100644 --- a/src/utils/parser_helpers.ts +++ b/src/utils/parser_helpers.ts @@ -262,10 +262,11 @@ export function findAndUpsertCookware( quantity, ); } catch (e) { - /* v8 ignore else -- expliciting error type -- @preserve */ if (e instanceof CannotAddTextValueError) { diagnostics.push(createDiagnostic("COOKLANG_W0401", {}, span)); return cookware.push(newCookware) - 1; + } else { + throw e; } } } diff --git a/test/parser_helpers.test.ts b/test/parser_helpers.test.ts index 9d57ef30..92a47fd1 100644 --- a/test/parser_helpers.test.ts +++ b/test/parser_helpers.test.ts @@ -922,6 +922,29 @@ describe("findAndUpsertCookware", () => { expect(diagnostics).toHaveDiagnostic("COOKLANG_W0401"); }); + it("should rethrow errors other than CannotAddTextValueError", () => { + const cookware: Cookware[] = [ + { + name: "oven", + quantity: { + type: "fixed", + value: { type: "fraction", num: 1, den: 0 }, + }, + }, + ]; + const newCookware: Cookware = { + name: "oven", + quantity: { + type: "fixed", + value: { type: "fraction", num: 1, den: 1 }, + }, + }; + + expect(() => findAndUpsertCookware(cookware, newCookware, true)).toThrow( + DivisionByZeroError, + ); + }); + it("should throw a ReferencedCookwareNotFoundError if a reference cookware does not exist", () => { const newCookware: Cookware = { name: "unreferenced-cookware", flags: [] }; expect(() => findAndUpsertCookware([], newCookware, true, [])).toThrow( diff --git a/test/shopping_cart.test.ts b/test/shopping_cart.test.ts index 0c9ca801..c60d4ac3 100644 --- a/test/shopping_cart.test.ts +++ b/test/shopping_cart.test.ts @@ -106,6 +106,7 @@ describe("initialisation", () => { catalog: productCatalog, list: shoppingList, }); + expect(shoppingCart.productCatalog).toBe(productCatalog); expect(shoppingCart.shoppingList).toBe(shoppingList); }); @@ -127,6 +128,23 @@ describe("initialisation", () => { }); }); +describe("unexpected matching errors", () => { + it("rethrows errors other than NoProductMatchError", () => { + const shoppingList = new ShoppingList(); + shoppingList.addRecipe(new Recipe("@flour{1%g}")); + const shoppingCart = new ShoppingCart({ + catalog: productCatalog, + list: shoppingList, + }); + const unexpected = new Error("Unexpected matching failure"); + Reflect.set(shoppingCart, "getOptimumMatch", () => { + throw unexpected; + }); + + expect(() => shoppingCart.buildCart()).toThrow(unexpected); + }); +}); + describe("buildCart", () => { it("should handle ingredients with no matching products", () => { const shoppingCart = new ShoppingCart();