Skip to content

Commit 6342d17

Browse files
authored
Merge pull request #1151 from googlefonts/better-tag-errors
Better reporting of InvalidTag errors
2 parents f036d57 + a005991 commit 6342d17

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

fontir/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ pub enum Error {
7171
mappings: Vec<(UserCoord, DesignCoord)>,
7272
value: DesignCoord,
7373
},
74-
#[error("Invalid tag")]
75-
InvalidTag(#[from] InvalidTag),
74+
#[error("Invalid tag '{raw_tag}': {cause}")]
75+
InvalidTag { raw_tag: String, cause: InvalidTag },
7676
#[error("Source file contained a construct we don't yet support: {0}")]
7777
UnsupportedConstruct(String),
7878
}

glyphs2fontir/src/source.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,11 @@ impl Work<Context, WorkId, Error> for StaticMetadataWork {
447447
.map_err(Error::VariationModelError)?;
448448
static_metadata.misc.selection_flags = selection_flags;
449449
if let Some(vendor_id) = font.vendor_id() {
450-
static_metadata.misc.vendor_id = Tag::from_str(vendor_id).map_err(Error::InvalidTag)?;
450+
static_metadata.misc.vendor_id =
451+
Tag::from_str(vendor_id).map_err(|cause| Error::InvalidTag {
452+
raw_tag: vendor_id.to_owned(),
453+
cause,
454+
})?;
451455
}
452456

453457
// Default per <https://github.com/googlefonts/glyphsLib/blob/cb8a4a914b0a33431f0a77f474bf57eec2f19bcc/Lib/glyphsLib/builder/custom_params.py#L1117-L1119>

glyphs2fontir/src/toir.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ fn to_ir_axis(
207207

208208
Ok(fontdrasil::types::Axis {
209209
name: axis.name.clone(),
210-
tag: Tag::from_str(&axis.tag).map_err(Error::InvalidTag)?,
210+
tag: Tag::from_str(&axis.tag).map_err(|cause| Error::InvalidTag {
211+
raw_tag: axis.tag.clone(),
212+
cause,
213+
})?,
211214
hidden: axis.hidden.unwrap_or(false),
212215
min: min.to_user(&converter),
213216
default: default.to_user(&converter),

ufo2fontir/src/source.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use norad::{
3030
};
3131
use write_fonts::{
3232
tables::{gdef::GlyphClassDef, os2::SelectionFlags},
33-
types::{InvalidTag, NameId, Tag},
33+
types::{NameId, Tag},
3434
OtRound,
3535
};
3636

@@ -305,8 +305,15 @@ impl Source for DesignSpaceIrSource {
305305
.designspace
306306
.axes
307307
.iter()
308-
.map(|a| Tag::from_str(&a.tag).map(|tag| (a.name.as_str(), tag)))
309-
.collect::<Result<HashMap<&str, Tag>, InvalidTag>>()?;
308+
.map(|a| {
309+
Tag::from_str(&a.tag)
310+
.map(|tag| (a.name.as_str(), tag))
311+
.map_err(|cause| Error::InvalidTag {
312+
cause,
313+
raw_tag: a.tag.clone(),
314+
})
315+
})
316+
.collect::<Result<HashMap<&str, Tag>, _>>()?;
310317
for (idx, source) in sources_default_first.iter().enumerate() {
311318
// Track files within each UFO
312319
// The UFO dir *must* exist since we were able to find fontinfo in it earlier
@@ -952,7 +959,11 @@ impl Work<Context, WorkId, Error> for StaticMetadataWork {
952959
.map_err(Error::VariationModelError)?;
953960
static_metadata.misc.selection_flags = selection_flags;
954961
if let Some(vendor_id) = &font_info_at_default.open_type_os2_vendor_id {
955-
static_metadata.misc.vendor_id = Tag::from_str(vendor_id).map_err(Error::InvalidTag)?;
962+
static_metadata.misc.vendor_id =
963+
Tag::from_str(vendor_id).map_err(|cause| Error::InvalidTag {
964+
raw_tag: vendor_id.to_owned(),
965+
cause,
966+
})?;
956967
}
957968

958969
// <https://github.com/googlefonts/glyphsLib/blob/cb8a4a914b0a33431f0a77f474bf57eec2f19bcc/Lib/glyphsLib/builder/custom_params.py#L1117-L1119>

ufo2fontir/src/toir.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ pub fn to_ir_axes(axes: &[designspace::Axis]) -> Result<Vec<fontdrasil::types::A
114114
}
115115

116116
pub fn to_ir_axis(axis: &designspace::Axis) -> Result<fontdrasil::types::Axis, Error> {
117-
let tag = Tag::from_str(&axis.tag).map_err(Error::InvalidTag)?;
117+
let tag = Tag::from_str(&axis.tag).map_err(|cause| Error::InvalidTag {
118+
raw_tag: axis.tag.clone(),
119+
cause,
120+
})?;
118121

119122
// <https://fonttools.readthedocs.io/en/latest/designspaceLib/xml.html#axis-element>
120123
let min = UserCoord::new(axis.minimum.unwrap());

0 commit comments

Comments
 (0)