Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to catch errors like - Failed to deserialize table, cannot read property records... #69

Closed
swampthang opened this issue Feb 4, 2017 · 8 comments

Comments

@swampthang
Copy link

I'm attempting to pull local fonts into an Electron app. All is working except, obviously, some of the fonts are not serializable and also seeing a cannot read property records of undefined.

Serialize errors from inspector look like:

Failed to decode downloaded font: file:///Library/Fonts/BigCaslon.ttf
OTS parsing error: cmap: failed to serialize table
Failed to decode downloaded font: file:///Library/Fonts/HeadlineA.ttf
OTS parsing error: OS/2: missing required table
Failed to decode downloaded font: file:///Library/Fonts/Diwan%20Thuluth.ttf
OTS parsing error: cmap: Failed to parse format 4 cmap subtable 0
Failed to decode downloaded font: file:///Library/Fonts/Gungseouche.ttf
OTS parsing error: OS/2: missing required table
Failed to decode downloaded font: file:///Library/Fonts/AppleGothic.ttf
OTS parsing error: OS/2: missing required table
Failed to decode downloaded font: file:///Library/Fonts/AppleMyungjo.ttf
OTS parsing error: OS/2: missing required table

undefined error looks like (I replaced the full path with 'localPath' before pasting here):

TTFFont.js:104 Uncaught (in promise) TypeError: Cannot read property 'records' of undefined
    at TTFFont.getName (localPath/node_modules/fontkit/index.js:12642:29)
    at TTFFont.get (localPath/node_modules/fontkit/index.js:12902:19)

I looked and it seems there is a font.fullName property but not a font.name property, so it seems to be assuming that if there's a fullName there has to be a .name property and I guess that's not guaranteed. Almost all the fonts are loading and working correctly. It's just the ones above that aren't.

I was getting an error when a fullName property was undefined but I added a check for that and it fixed that issue....

if( font.fullName === undefined ) return;

I tried adding...

  if( font.name === undefined ) return;

... but it doesn't seem to keep it from proceeding.

This is an app that could be run on several different machines so font sets will vary. I'd like a more elegant way to allow these to fail and then just jump out of using that particular font file. Just fyi, I'm only processing otf, ttf, woff and woff2 files. Everything else gets removed from the array.

@swampthang
Copy link
Author

Noticing that when the script fails, it kills the process so all fonts after that are not being loaded. Looking at where the script fails, the font that seems to be the culprit is in the attached zip file.
Jazz.ttf.zip

@swampthang
Copy link
Author

Here are a couple of references to the OTS parsing error:
https://bugs.chromium.org/p/chromium/issues/detail?id=527165
khaledhosny/ots#80
khaledhosny/ots@937c9c3

@swampthang
Copy link
Author

Looking at this...
https://chromium.googlesource.com/external/github.com/khaledhosny/ots/+/refs/heads/master/docs/DesignDoc.md
I noticed that the goal of OTS was not necessarily to nuke the fonts. So I spoke too soon calling the OTS notifications 'errors'. They're actually warnings. The fonts are being loaded. Not sure if this is a problem for the app but so far it's working. I was able to overcome the font.name === undefined error as well.

@devongovett
Copy link
Member

Those OTS issues aren't caused by fontkit. OTS is a font validator used by Chrome to prevent security issues with web fonts. If you have an issue with fontkit specifically, could you post a code example demonstrating the problem and the font in question? Thanks!

@swampthang
Copy link
Author

Was just wondering if you had any kind of listener for those warnings and a way to suppress them.

@swampthang
Copy link
Author

After creating a font object, is there a way to get the font file path back out of the object? Been digging around in the object and there's a lot in there. Assumed you had to have it stored in there somewhere.
Thanks.

@devongovett
Copy link
Member

fontkit objects can be created in many ways, including from files or buffers. The filename is not held onto once the font is read into memory. You'll need to do that yourself.

@digitalnature
Copy link

To prevent this, you can wrap the property call in a try-catch block


try{
   font.fullName;
 }catch(e){
   console.log(e.message);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants