Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

call callback with error instead of throwing #12

Merged
merged 2 commits into from Jul 28, 2016
Merged

call callback with error instead of throwing #12

merged 2 commits into from Jul 28, 2016

Conversation

tmcw
Copy link
Contributor

@tmcw tmcw commented Jul 22, 2016

@miccolis do you know how this branch is triggered so we could write test coverage for it?


if (faces.length > 1) throw new Error('woah multifont!');
if (faces.length > 1) {
return new Error('Multiple fonts are not yet supported.');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be return callback(new Error...)) no?

@lbud
Copy link
Contributor

lbud commented Jul 22, 2016

bitmoji

oooooops

do you know how this branch is triggered so we could write test coverage for it?

The reason there wasn't a test for it was because we didn't know how it was triggered — the FreeType spec says certain fonts can have multiple faces in one file, but this is rare. @miccolis did the log reveal which font crashed it?

@miccolis
Copy link

@lbud nope, in typical crashy crash fashion, it just crashed and all I got was this lousy stack trace...

@tmcw
Copy link
Contributor Author

tmcw commented Jul 22, 2016

Okay, next commit includes Noto, hits decent coverage numbers, switches to TAP. Unfortunately node-fontnik also has its own throw, so I'm wrapping the call in a try/catch now. Upstream for that is mapbox/node-fontnik#112

@@ -29,7 +31,31 @@ tape('handle undefined style_name', function(t) {
});
});

tape('font machine 256-511', function(t) {
test('handle font not found', function(t) {
fontmachine.makeGlyphs({font: 'NOT-FOUND', filetype: '.ttc'}, function(err, font) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... this is just passing a string directly through to fontnik.load, when the API requires passing a Buffer. Adding some argument validation (opts.font instanceof Buffer && opts.callback instanceof Function) at the beginning of makeGlyphs seems like a better approach than try/catch around fontnik.load or trying to change this upstream to pass an error through to the callback? If an attempt to read a font from disk fails in a downstream module, shouldn't that error be handled before trying to pass along something invalid to fontmachine?

@mikemorris
Copy link
Contributor

mikemorris commented Jul 28, 2016

Clarified the wording of the multi-face font error callback and added some checks that will throw if the API is misused, fix here and switch to tap look 💯 to me.

@mikemorris mikemorris merged commit 3cade44 into master Jul 28, 2016
@mikemorris mikemorris deleted the nothrow branch July 28, 2016 21:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants