d2lang/d2 · error
expected "stroke-dash" to be a number between 0 and 10
Error message
expected "stroke-dash" to be a number between 0 and 10
What it means
The 'stroke-dash' style key must parse as an integer between 0 and 10 inclusive. This error is returned when strconv.Atoi fails or the value falls outside 0–10.
Source
Thrown at d2graph/d2graph.go:365
return fmt.Errorf(`expected "fill-pattern" to be one of: %s`, strings.Join(d2ast.FillPatterns, ", "))
}
s.FillPattern.Value = value
case "stroke-width":
if s.StrokeWidth == nil {
break
}
f, err := strconv.Atoi(value)
if err != nil || (f < 0 || f > 15) {
return errors.New(`expected "stroke-width" to be a number between 0 and 15`)
}
s.StrokeWidth.Value = value
case "stroke-dash":
if s.StrokeDash == nil {
break
}
f, err := strconv.Atoi(value)
if err != nil || (f < 0 || f > 10) {
return errors.New(`expected "stroke-dash" to be a number between 0 and 10`)
}
s.StrokeDash.Value = value
case "border-radius":
if s.BorderRadius == nil {
break
}
f, err := strconv.Atoi(value)
if err != nil || (f < 0) {
return errors.New(`expected "border-radius" to be a number greater or equal to 0`)
}
s.BorderRadius.Value = value
case "shadow":
if s.Shadow == nil {
break
}
_, err := strconv.ParseBool(value)
if err != nil {
return errors.New(`expected "shadow" to be true or false`)View on GitHub (pinned to 0d69dca6f5)
Solutions
- Use an integer from 0 to 10 for stroke-dash.
- Replace keyword values like "dashed" with the numeric equivalent.
- Clamp values above 10 down to 10.
Example fix
// before x.style.stroke-dash: dashed // after x.style.stroke-dash: 4
Defensive patterns
Strategy: validation
Validate before calling
n, err := strconv.Atoi(v)
if err != nil || n < 0 || n > 10 {
return fmt.Errorf("stroke-dash %q must be an integer 0-10", v)
} Type guard
func validStrokeDash(s string) bool { n, err := strconv.Atoi(s); return err == nil && n >= 0 && n <= 10 } Try / catch
if err := applyStyle("stroke-dash", value); err != nil {
if strings.Contains(err.Error(), "stroke-dash") {
value = "0" // solid line default
}
} Prevention
- Use numeric dash values 0–10, not CSS keywords.
- Clamp before assigning to StrokeDash.Value.
- Document the 0–10 limit wherever users input dash styles.
When it happens
Trigger: Setting style 'stroke-dash' to a non-integer ("dashed", "1.5") or out-of-range integer (e.g. 12, -3).
Common situations: D2 authors trying CSS dash-style keywords or picking dash sizes above the allowed maximum.
Related errors
- expected "stroke-width" to be a number between 0 and 15
- expected "border-radius" to be a number greater or equal to
- expected "opacity" to be a number between 0.0 and 1.0
- expected "stroke" to be a valid named color ("orange"), a he
- expected "fill" to be a valid named color ("orange"), a hex
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/70e580b8b607ebdc.
Report an issue: GitHub.