Skip to content

Conversation

@simoncozens
Copy link
Contributor

This PR bans unwrap, expect and indexing slicing (i.e. panicable operations) from fontdrasil. unwrap() is replaced either with a ok_or or explained with an annotation.

This does change the API somewhat; creating coordinate convertors, and converting coordinates, returns a Result.

There is also an unrelated change to the version of vergen-gitcl used by fontc. Without this, we were using vergen-gitcl 1.0 which pulled in vergen v9.1.0, which had a very different API to the one vergen-gitcl expected. So I couldn't get things to compile without it.

Fixes #1879

@simoncozens simoncozens force-pushed the safe-fontdrasil branch 2 times, most recently from 818bbc3 to ee99af4 Compare January 21, 2026 13:11
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

looks good simon, thanks for taking this on!

Comment on lines +976 to +978
if let Some(weight) = weights.last() {
trace!(" {} {:?}", loc_idx, weight);
}
Copy link
Member

Choose a reason for hiding this comment

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

alternatively we could just remove the unwrap, and we will debug-print the Option.

Comment on lines +837 to +841
assert!(
minmax.contains_key(tag),
"axis_order contained axes not in locations"
);
#[allow(clippy::unwrap_used)]
Copy link
Member

Choose a reason for hiding this comment

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

totally not necessary to change but: this could also be expressed a bit more concisely by just using expect in place of unwrap below, with the same text as your assertion here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but I see a philosophical difference. I want to ban expects because they're just unwraps with an error message. I know the actual outcome is the same, but assert affirmatively signals that we're testing an internal invariant ("In a mad world this might fail, let's make sure and bug out if it does"), while .unwrap/.expect is "I am positively sure this won't fail".

Co-authored-by: Colin Rofls <colin@cmyr.net>
@simoncozens simoncozens added this pull request to the merge queue Jan 21, 2026
Merged via the queue into main with commit 4411e09 Jan 21, 2026
13 checks passed
@simoncozens simoncozens deleted the safe-fontdrasil branch January 21, 2026 17:11
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

Successfully merging this pull request may close these issues.

[fontdrasil] unwrap in convert() can panic

2 participants