d2lang/d2 · error
expected "bold" to be true or false
Error message
expected "bold" to be true or false
What it means
D2's style-setting code parses the "bold" style value with strconv.ParseBool; non-boolean values return this error and the style is not applied. Only runs when s.Bold is non-nil.
Source
Thrown at d2graph/d2graph.go:444
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`)
}
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`)View on GitHub (pinned to 0d69dca6f5)
Solutions
- Change the value to "true" or "false" (e.g. `x.bold: true`).
- Use 1 or 0 as accepted boolean numerics.
- Remove the bold key to keep the default weight.
- Validate style maps with strconv.ParseBool before assignment.
Example fix
// before (D2) x: my shape x.bold: strong // after x: my shape x.bold: true
Defensive patterns
Strategy: validation
Validate before calling
func validStyleBool(v string) bool {
_, err := strconv.ParseBool(v)
return err == nil
}
// before applying: if !validStyleBool(boldVal) { /* 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("bold", val); err != nil {
if strings.Contains(err.Error(), `"bold" to be true or false`) {
// fallback: default weight
val = "false"
}
} Prevention
- Use true/false or 1/0 for the bold style key.
- Convert strong/yes inputs to booleans before applying.
- Validate boolean style keys in a pre-render lint pass.
- Omit bold instead of setting it to an invalid value.
When it happens
Trigger: Setting style key "bold" to a value strconv.ParseBool rejects, e.g. `x.bold: yes`, `bold: on`, or `bold: strong`.
Common situations: Typing "yes"/"on"/"strong" for bold text, or YAML/JSON configs using language-specific truthy keywords that D2 does not accept.
Related errors
- expected "shadow" to be true or false
- expected "3d" to be true or false
- expected "multiple" to be true or false
- expected "animated" 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/22a46fab54e0c6e1.
Report an issue: GitHub.