d2lang/d2 · error

expected "filled" to be true or false

Error message

expected "filled" to be true or false

What it means

D2's style-setting code parses the "filled" style value with strconv.ParseBool; non-boolean values return this error and the fill is not applied. Runs only when s.Filled is non-nil.

Source

Thrown at d2graph/d2graph.go:471

			return errors.New(`expected "italic" to be true or false`)
		}
		s.Italic.Value = value
	case "underline":
		if s.Underline == nil {
			break
		}
		_, err := strconv.ParseBool(value)
		if err != nil {
			return errors.New(`expected "underline" to be true or false`)
		}
		s.Underline.Value = value
	case "filled":
		if s.Filled == nil {
			break
		}
		_, err := strconv.ParseBool(value)
		if err != nil {
			return errors.New(`expected "filled" to be true or false`)
		}
		s.Filled.Value = value
	case "double-border":
		if s.DoubleBorder == nil {
			break
		}
		_, err := strconv.ParseBool(value)
		if err != nil {
			return errors.New(`expected "double-border" to be true or false`)
		}
		s.DoubleBorder.Value = value
	case "text-transform":
		if s.TextTransform == nil {
			break
		}
		if !go2.Contains(d2ast.TextTransforms, strings.ToLower(value)) {
			return fmt.Errorf(`expected "text-transform" to be one of (%s)`, strings.Join(d2ast.TextTransforms, ", "))
		}

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Change the value to "true" or "false" (e.g. `x.filled: true`).
  2. If you intended a color, use the fill/fill-color style key instead of filled.
  3. Use 1 or 0 as numeric boolean literals.
  4. Pre-validate with strconv.ParseBool before assigning the style.

Example fix

// before (D2)
x: my shape
x.filled: green
// after
x: my shape
x.filled: true
x.fill-color: green
Defensive patterns

Strategy: validation

Validate before calling

func validStyleBool(v string) bool {
	_, err := strconv.ParseBool(v)
	return err == nil
}
// before applying: if !validStyleBool(filledVal) { /* 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("filled", val); err != nil {
	if strings.Contains(err.Error(), `"filled" to be true or false`) {
		// fallback: default fill, or reroute color to fill-color
		val = "false"
	}
}

Prevention

When it happens

Trigger: Setting style key "filled" to a value strconv.ParseBool rejects, e.g. `x.filled: yes`, `filled: on`, or a color string mistakenly placed in filled (e.g. `filled: green` — use `fill` or `fill-color` for colors).

Common situations: Confusing "filled" (boolean) with the fill-color style and passing a color, or using "yes"/"on" truthy words from other config languages.

Related errors


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