d2lang/d2 · error
"%v" is not a valid font in our system
Error message
"%v" is not a valid font in our system
What it means
The "font" style key must name a font family present in d2fonts.D2_FONT_TO_FAMILY. The value is checked case-insensitively; unknown names produce this error naming the offending value.
Source
Thrown at d2graph/d2graph.go:409
if err != nil {
return errors.New(`expected "3d" to be true or false`)
}
s.ThreeDee.Value = value
case "multiple":
if s.Multiple == nil {
break
}
_, err := strconv.ParseBool(value)
if err != nil {
return errors.New(`expected "multiple" to be true or false`)
}
s.Multiple.Value = value
case "font":
if s.Font == nil {
break
}
if _, ok := d2fonts.D2_FONT_TO_FAMILY[strings.ToLower(value)]; !ok {
return fmt.Errorf(`"%v" is not a valid font in our system`, value)
}
s.Font.Value = strings.ToLower(value)
case "font-size":
if s.FontSize == nil {
break
}
f, err := strconv.Atoi(value)
if err != nil || (f < 8 || f > 100) {
return errors.New(`expected "font-size" to be a number between 8 and 100`)
}
s.FontSize.Value = value
case "font-color":
if s.FontColor == nil {
break
}
if !color.ValidColor(value) {
return errors.New(`expected "font-color" to be a valid named color ("orange"), a hex code ("#f0ff3a"), or a gradient ("linear-gradient(red, blue)")`)
}View on GitHub (pinned to 0d69dca6f5)
Solutions
- Use a built-in family name listed in d2fonts.D2_FONT_TO_FAMILY (lowercase matching)
- Register a custom font by providing the TTF files via the font flags so the family becomes valid
- Fix spelling/spacing of the font name
Example fix
// before x.style.font: Arial // after x.style.font: Source Sans Pro
Defensive patterns
Strategy: validation
Validate before calling
if _, ok := d2fonts.D2_FONT_TO_FAMILY[strings.ToLower(fontName)]; !ok {
// invalid font family — register via --font-* flags or pick a built-in
} Type guard
func validFontFamily(v string) bool {
_, ok := d2fonts.D2_FONT_TO_FAMILY[strings.ToLower(v)]
return ok
} Try / catch
if err := obj.SetStyle("font", v); err != nil {
return fmt.Errorf("font %q unavailable: %v", v, err)
} Prevention
- Use built-in family names from D2_FONT_TO_FAMILY
- Register custom fonts with --font-regular etc. before using them in styles
- Normalize names to lowercase with exact spacing
When it happens
Trigger: Setting `style.font` on a shape/element to a value not in D2_FONT_TO_FAMILY — e.g. `font: Arial` or `font: Comic Sans` instead of built-in families like Source Sans Pro, Source Code Pro, or custom fonts loaded via loadFonts.
Common situations: Assuming any system-installed font works, forgetting to register a custom font family via the --font-* flags, or using a font name with wrong spacing/casing combined with missing registration.
Related errors
- expected "shadow" to be true or false
- expected "3d" to be true or false
- expected "multiple" to be true or false
- expected "font-size" to be a number between 8 and 100
- expected "font-color" to be a valid named color ("orange"),
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/609bdc1b5913daf9.
Report an issue: GitHub.