Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/websafe/fetch-easyeda-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
38 changes: 38 additions & 0 deletions tests/fetch-tests/c99-assembly-part-error-390.test.ts
Original file line number Diff line number Diff line change
@@ -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"/)
})
Loading