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

  1. Change the value to "true" or "false" (e.g. `x.animated: true`).
  2. Use 1 or 0 as numeric boolean literals.
  3. Remove the animated key for the default (no animation).
  4. 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

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


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/46ec2011fb415c64. Report an issue: GitHub.