diff --git a/lib/websafe/fetch-easyeda-json.ts b/lib/websafe/fetch-easyeda-json.ts index b45e956f..865d23ff 100644 --- a/lib/websafe/fetch-easyeda-json.ts +++ b/lib/websafe/fetch-easyeda-json.ts @@ -119,7 +119,12 @@ export async function fetchEasyEDAComponent( const searchResult = await searchResponse.json() if (!searchResult.success || !searchResult.result.lists.lcsc.length) { - throw new Error("Component not found") + if (/^C99\d{6,}$/i.test(jlcpcbPartNumber)) { + throw new Error( + `Component not found: "${jlcpcbPartNumber}" is a JLCPCB assembly-catalog part number (C99xxxxxxx). These parts frequently have no EasyEDA symbol/footprint behind them, so there is nothing to convert — try searching for the underlying manufacturer part number instead.`, + ) + } + throw new Error(`Component not found: "${jlcpcbPartNumber}"`) } const bestMatchComponent = diff --git a/tests/fetch-tests/c99-assembly-part-error-390.test.ts b/tests/fetch-tests/c99-assembly-part-error-390.test.ts new file mode 100644 index 00000000..253842e8 --- /dev/null +++ b/tests/fetch-tests/c99-assembly-part-error-390.test.ts @@ -0,0 +1,38 @@ +import { expect, it } from "bun:test" +import { fetchEasyEDAComponent } from "lib/websafe/fetch-easyeda-json" + +// https://github.com/tscircuit/easyeda-converter/issues/390 +// +// C99xxxxxxx numbers are JLCPCB assembly-catalog entries that often have no +// EasyEDA symbol/footprint behind them (verified: both the search API and the +// products API return nothing for C9900033429). The error should say so +// instead of a bare "Component not found". +it("explains that C99 assembly parts have no EasyEDA data", async () => { + const emptySearchFetch = (async () => + new Response( + JSON.stringify({ + success: true, + result: { lists: { lcsc: [] } }, + }), + { status: 200 }, + )) as unknown as typeof globalThis.fetch + + expect( + fetchEasyEDAComponent("C9900033429", { fetch: emptySearchFetch }), + ).rejects.toThrow(/assembly-catalog part number/) +}) + +it("includes the part number in the generic not-found error", async () => { + const emptySearchFetch = (async () => + new Response( + JSON.stringify({ + success: true, + result: { lists: { lcsc: [] } }, + }), + { status: 200 }, + )) as unknown as typeof globalThis.fetch + + expect( + fetchEasyEDAComponent("C1234", { fetch: emptySearchFetch }), + ).rejects.toThrow(/Component not found: "C1234"/) +})