d2lang/d2 · error
expected "font-size" to be a number between 8 and 100
Error message
expected "font-size" to be a number between 8 and 100
What it means
D2 validates the "font-size" style by parsing it as an integer and requiring it to be between 8 and 100 inclusive. A value that is not an integer, or outside that range, returns this error and the style is rejected.
Source
Thrown at d2graph/d2graph.go:418
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)")`)
}
s.FontColor.Value = value
case "animated":
if s.Animated == nil {
break
}
_, err := strconv.ParseBool(value)
if err != nil {
return errors.New(`expected "animated" to be true or false`)
}View on GitHub (pinned to 0d69dca6f5)
Solutions
- Use an integer between 8 and 100 (e.g. `x.font-size: 24`).
- Remove units like "px" or "em" from the value.
- Clamp generated values in code: if f < 8 { f = 8 }; if f > 100 { f = 100 }.
- For larger text, use container/scale options instead of exceeding the font-size cap.
Example fix
// before (D2) x: my shape x.font-size: 150 // after x: my shape x.font-size: 100
Defensive patterns
Strategy: validation
Validate before calling
func validFontSize(v string) (string, bool) {
f, err := strconv.Atoi(v)
if err != nil || f < 8 || f > 100 {
return "", false
}
return v, true
}
// before applying: fs, ok := validFontSize(val); if !ok { fs = strconv.Itoa(clamp) } Type guard
func isFontSizeInRange(v string) bool {
f, err := strconv.Atoi(v)
return err == nil && f >= 8 && f <= 100
} Try / catch
if err := obj.SetStyle("font-size", val); err != nil {
if strings.Contains(err.Error(), `"font-size" to be a number between 8 and 100`) {
// fallback to a safe default
val = "16"
}
} Prevention
- Keep font-size an integer within 8–100.
- Strip units (px/em/rem) from user input before applying.
- Clamp values in code instead of passing them raw.
- Reject decimals (12.5) early — Atoi does not parse floats.
When it happens
Trigger: Setting style key "font-size" to a non-integer string (e.g. "12.5", "big") or an integer below 8 or above 100 (e.g. `x.font-size: 150`).
Common situations: Users request large headline text beyond the cap (e.g. 200), use pixel units like "14px", or decimals like "12.5" copied from CSS.
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-color" to be a valid named color ("orange"),
- expected "animated" to be true or false
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/ae9536e98e623001.
Report an issue: GitHub.