d2lang/d2 · error
expected "animated" to be true or false
Error message
expected "animated" to be true or false
What it means
D2's style-setting code parses the "animated" style value with strconv.ParseBool and returns this error when it is not a boolean literal. Validation only applies when s.Animated is non-nil.
Source
Thrown at d2graph/d2graph.go:435
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`)
}
s.Animated.Value = value
case "bold":
if s.Bold == nil {
break
}
_, err := strconv.ParseBool(value)
if err != nil {
return errors.New(`expected "bold" to be true or false`)
}
s.Bold.Value = value
case "italic":
if s.Italic == nil {
break
}
_, err := strconv.ParseBool(value)
if err != nil {
return errors.New(`expected "italic" to be true or false`)View on GitHub (pinned to 0d69dca6f5)
Solutions
- Change the value to "true" or "false" (e.g. `x.animated: true`).
- Use 1 or 0 as numeric boolean literals.
- Remove the animated key for the default (no animation).
- Sanitize user style input with strconv.ParseBool before passing it to D2.
Example fix
// before (D2) x: my shape x.animated: forever // after x: my shape x.animated: true
Defensive patterns
Strategy: validation
Validate before calling
func validStyleBool(v string) bool {
_, err := strconv.ParseBool(v)
return err == nil
}
// before applying: if !validStyleBool(animatedVal) { /* fix or reject */ } Type guard
func isParseBoolValue(s string) bool {
switch s {
case "1", "t", "T", "TRUE", "true", "True", "0", "f", "F", "FALSE", "false", "False":
return true
}
return false
} Try / catch
if err := obj.SetStyle("animated", val); err != nil {
if strings.Contains(err.Error(), `"animated" to be true or false`) {
// fallback: disable animation
val = "false"
}
} Prevention
- Use true/false or 1/0 for the animated style key.
- Map words like always/never to booleans in your config layer.
- Lint diagrams for boolean style keys before rendering.
- Unset animated keys are ignored — remove rather than misvalue them.
When it happens
Trigger: Setting style key "animated" to a non-boolean value, e.g. `x.animated: yes` or `animated: always`, on shapes/connections supporting animation.
Common situations: Users describe animation intent with words like "yes", "always", "forever" instead of a boolean; also occurs with configs generated from non-Go boolean formats.
Related errors
- expected "shadow" to be true or false
- expected "3d" to be true or false
- expected "multiple" to be true or false
- expected "bold" to be true or false
- expected "italic" to be true or false
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/46ec2011fb415c64.
Report an issue: GitHub.