d2lang/d2 · error
expected "3d" to be true or false
Error message
expected "3d" to be true or false
What it means
D2's style-setting code parses the "3d" style value with strconv.ParseBool and returns this error when the value is not a boolean literal. s.ThreeDee is only validated when it is non-nil (style explicitly marked as set).
Source
Thrown at d2graph/d2graph.go:392
return errors.New(`expected "border-radius" to be a number greater or equal to 0`)
}
s.BorderRadius.Value = value
case "shadow":
if s.Shadow == nil {
break
}
_, err := strconv.ParseBool(value)
if err != nil {
return errors.New(`expected "shadow" to be true or false`)
}
s.Shadow.Value = value
case "3d":
if s.ThreeDee == nil {
break
}
_, err := strconv.ParseBool(value)
if err != nil {
return errors.New(`expected "3d" to be true or false`)
}
s.ThreeDee.Value = value
case "multiple":
if s.Multiple == nil {
break
}
_, err := strconv.ParseBool(value)
if err != nil {
return errors.New(`expected "multiple" to be true or false`)
}
s.Multiple.Value = value
case "font":
if s.Font == nil {
break
}
if _, ok := d2fonts.D2_FONT_TO_FAMILY[strings.ToLower(value)]; !ok {
return fmt.Errorf(`"%v" is not a valid font in our system`, value)
}View on GitHub (pinned to 0d69dca6f5)
Solutions
- Change the 3d value to "true" or "false" (e.g. `x.3d: true`).
- Use 1 or 0 as accepted numeric boolean literals.
- Remove the 3d key if the default (disabled) look is fine.
- Validate user-supplied style maps against ParseBool before passing them to the library.
Example fix
// before (D2) x: my shape x.3d: on // after x: my shape x.3d: true
Defensive patterns
Strategy: validation
Validate before calling
func validStyleBool(v string) bool {
_, err := strconv.ParseBool(v)
return err == nil
}
// before applying: if !validStyleBool(threeDVal) { /* 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("3d", val); err != nil {
if strings.Contains(err.Error(), `"3d" to be true or false`) {
// fallback: disable 3d
val = "false"
}
} Prevention
- Use true/false or 1/0 for the 3d style key.
- Convert yes/on/off from user config to canonical booleans before applying.
- Add a lint step validating boolean style keys in CI.
- Unset 3d keys are ignored — remove them instead of setting junk values.
When it happens
Trigger: Setting style key "3d" to a value strconv.ParseBool rejects, e.g. `x.3d: yes`, `3d: on`, or `3d: 2` in a D2 diagram or via the programmatic style setter.
Common situations: Users type "yes"/"on" instead of "true" for the 3D look, or copy boolean values from YAML/JSON configs that use language-specific truthy keywords.
Related errors
- expected "shadow" to be true or false
- expected "multiple" to be true or false
- expected "animated" 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/3b83a6c860fcea0f.
Report an issue: GitHub.