From 250d9ed81db2866102a2668974abc4170cb6e3b4 Mon Sep 17 00:00:00 2001 From: CodeForFee Date: Thu, 14 May 2026 06:53:55 -0700 Subject: [PATCH] Improve missing footprint function errors --- src/footprinter.ts | 28 ++++++++++++++-------------- tests/fp-string-error.test.ts | 10 ++++++++-- tests/vssop.test.ts | 3 ++- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/footprinter.ts b/src/footprinter.ts index fa51a3b4..592b4e6f 100644 --- a/src/footprinter.ts +++ b/src/footprinter.ts @@ -337,6 +337,17 @@ export const getFootprintNamesByType = (): { } } +const createFootprintFunctionNotFoundError = (target: any) => { + const fn = target.fn + const source = target.string ? `, from string "${target.string}"` : "" + const received = + typeof fn === "string" && fn.length > 0 ? `"${fn}"` : "no function" + + return new Error( + `Function not found for footprinter ${received}${source}. Specify a valid function like .dip, .lr, .p, etc.`, + ) +} + export const footprinter = (): Footprinter & { string: typeof string getFootprintNames: string[] @@ -363,27 +374,16 @@ export const footprinter = (): Footprinter & { } if (!FOOTPRINT_FN[target.fn]) { - throw new Error( - `Invalid footprint function, got "${target.fn}"${ - target.string ? `, from string "${target.string}"` : "" - }`, - ) + throw createFootprintFunctionNotFoundError(target) } return () => { - // TODO improve error - throw new Error( - `No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${prop}"`, - ) + throw createFootprintFunctionNotFoundError(target) } } if (prop === "json") { if (!FOOTPRINT_FN[target.fn]) { - throw new Error( - `Invalid footprint function, got "${target.fn}"${ - target.string ? `, from string "${target.string}"` : "" - }`, - ) + throw createFootprintFunctionNotFoundError(target) } return () => FOOTPRINT_FN[target.fn](target).parameters } diff --git a/tests/fp-string-error.test.ts b/tests/fp-string-error.test.ts index 1e6c4227..ccecb73b 100644 --- a/tests/fp-string-error.test.ts +++ b/tests/fp-string-error.test.ts @@ -1,8 +1,14 @@ -import { test, expect } from "bun:test" +import { expect, test } from "bun:test" import { fp } from "src/footprinter" test("fp.string error", () => { expect(() => fp.string("nonexistentfn4_p3").circuitJson()).toThrow( - 'Invalid footprint function, got "nonexistentfn", from string "nonexistentfn4_p3"', + 'Function not found for footprinter "nonexistentfn", from string "nonexistentfn4_p3". Specify a valid function like .dip, .lr, .p, etc.', + ) +}) + +test("fp builder error when no footprint function is selected", () => { + expect(() => fp().soup()).toThrow( + "Function not found for footprinter no function. Specify a valid function like .dip, .lr, .p, etc.", ) }) diff --git a/tests/vssop.test.ts b/tests/vssop.test.ts index 0b12cc27..ed6d7899 100644 --- a/tests/vssop.test.ts +++ b/tests/vssop.test.ts @@ -123,7 +123,8 @@ test("invalid_vssop6", () => { } catch (error) { const e = error as Error expect(e).toBeInstanceOf(Error) - expect(e.message).toContain("Invalid footprint function") + expect(e.message).toContain("Function not found for footprinter") + expect(e.message).toContain('"invalid"') } })