fontsource / google-font-metadata

A metadata generator that fetches and parses the Google Fonts API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error while parsing APIv2

TomOne opened this issue · comments

Describe the bug

Attempting to parse APIv2 throws the following error:

ERROR Cannot convert undefined or null to object
at Function.keys ()
at processCSS (src/api-parser-v2.ts:206:29)
at processQueue (src/api-parser-v2.ts:238:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at (src/api-parser-v2.ts:263:5)
at (node_modules/.pnpm/p-queue@7.4.1/node_modules/p-queue/dist/index.js:118:36)

node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^

TypeError: Cannot convert undefined or null to object
at Function.keys ()
at processCSS (/home/user/Code/google-font-metadata/src/api-parser-v2.ts:206:29)
at processQueue (/home/user/Code/google-font-metadata/src/api-parser-v2.ts:238:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at (/home/user/Code/google-font-metadata/src/api-parser-v2.ts:263:5)
at (/home/user/Code/google-font-metadata/node_modules/.pnpm/p-queue@7.4.1/node_modules/p-queue/dist/index.js:118:36)

Node.js v20.10.0

It looks like the newly added typeface Linefont (added on 2023-10-25) is the culprit.

Steps to Reproduce

Run npm run gfm parse --v2

Expected behavior

No response

Version

5.2.0

OS

Linux

Browser

No response

Additional context

No response

commented

Looks like the Google Fonts team has explicitly decided to not support Linefont as a static font. google/fonts#4630 (comment)

It's a little bit annoying since we have no indication from the APIs we are dependent on if they would do something like this again for another font. Nor do I think it's a sustainable idea to let our build pipelines hard throw if something like this happens again.

I think I'll switch this error to a warning in logs instead of throwing, and also explicitly add a blocklist of fonts that should ignore generating data for static fonts. That's going to break some assumptions made downstream in the Fontsource API as it assumes the existence of static metadata to serve variable metadata, so it may be considered a breaking change for this library... but older versions just won't work anyways with this upstream change so it will just be a patch bump.

commented

New release should be published to NPM now. 🎉