d2lang/d2 · error

expected "italic" to be true or false

Error message

expected "italic" to be true or false

What it means

D2's style-setting code parses the "italic" style value with strconv.ParseBool; non-boolean values return this error. The check applies only when s.Italic is non-nil.

Source

Thrown at d2graph/d2graph.go:453

			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`)
		}
		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`)

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Change the value to "true" or "false" (e.g. `x.italic: true`).
  2. Use 1 or 0 as numeric boolean literals.
  3. Remove the italic key for the default style.
  4. Pre-validate the style value in the caller with strconv.ParseBool.

Example fix

// before (D2)
x: my shape
x.italic: yes
// after
x: my shape
x.italic: true
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Setting style key "italic" to a non-boolean value, e.g. `x.italic: yes` or `italic: slanted`.

Common situations: Using descriptive words like "yes"/"slanted" instead of "true", or interpolating config values that are not canonical boolean strings.

Related errors


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