{"record":{"id":"46ec2011fb415c64","repo":"d2lang/d2","slug":"expected-animated-to-be-true-or-false","errorCode":null,"errorMessage":"expected \"animated\" to be true or false","messagePattern":"expected \"animated\" to be true or false","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":435,"sourceCode":"\t\tif err != nil || (f < 8 || f > 100) {\n\t\t\treturn errors.New(`expected \"font-size\" to be a number between 8 and 100`)\n\t\t}\n\t\ts.FontSize.Value = value\n\tcase \"font-color\":\n\t\tif s.FontColor == nil {\n\t\t\tbreak\n\t\t}\n\t\tif !color.ValidColor(value) {\n\t\t\treturn errors.New(`expected \"font-color\" to be a valid named color (\"orange\"), a hex code (\"#f0ff3a\"), or a gradient (\"linear-gradient(red, blue)\")`)\n\t\t}\n\t\ts.FontColor.Value = value\n\tcase \"animated\":\n\t\tif s.Animated == nil {\n\t\t\tbreak\n\t\t}\n\t\t_, err := strconv.ParseBool(value)\n\t\tif err != nil {\n\t\t\treturn errors.New(`expected \"animated\" to be true or false`)\n\t\t}\n\t\ts.Animated.Value = value\n\tcase \"bold\":\n\t\tif s.Bold == nil {\n\t\t\tbreak\n\t\t}\n\t\t_, err := strconv.ParseBool(value)\n\t\tif err != nil {\n\t\t\treturn errors.New(`expected \"bold\" to be true or false`)\n\t\t}\n\t\ts.Bold.Value = value\n\tcase \"italic\":\n\t\tif s.Italic == nil {\n\t\t\tbreak\n\t\t}\n\t\t_, err := strconv.ParseBool(value)\n\t\tif err != nil {\n\t\t\treturn errors.New(`expected \"italic\" to be true or false`)","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L417-L453","documentation":"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.","triggerScenarios":"Setting style key \"animated\" to a non-boolean value, e.g. `x.animated: yes` or `animated: always`, on shapes/connections supporting animation.","commonSituations":"Users describe animation intent with words like \"yes\", \"always\", \"forever\" instead of a boolean; also occurs with configs generated from non-Go boolean formats.","solutions":["Change the value to \"true\" or \"false\" (e.g. `x.animated: true`).","Use 1 or 0 as numeric boolean literals.","Remove the animated key for the default (no animation).","Sanitize user style input with strconv.ParseBool before passing it to D2."],"exampleFix":"// before (D2)\nx: my shape\nx.animated: forever\n// after\nx: my shape\nx.animated: true","handlingStrategy":"validation","validationCode":"func validStyleBool(v string) bool {\n\t_, err := strconv.ParseBool(v)\n\treturn err == nil\n}\n// before applying: if !validStyleBool(animatedVal) { /* fix or reject */ }","typeGuard":"func isParseBoolValue(s string) bool {\n\tswitch s {\n\tcase \"1\", \"t\", \"T\", \"TRUE\", \"true\", \"True\", \"0\", \"f\", \"F\", \"FALSE\", \"false\", \"False\":\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":"if err := obj.SetStyle(\"animated\", val); err != nil {\n\tif strings.Contains(err.Error(), `\"animated\" to be true or false`) {\n\t\t// fallback: disable animation\n\t\tval = \"false\"\n\t}\n}","preventionTips":["Use true/false or 1/0 for the animated style key.","Map words like always/never to booleans in your config layer.","Lint diagrams for boolean style keys before rendering.","Unset animated keys are ignored — remove rather than misvalue them."],"tags":["d2","style-validation","boolean-parsing","strconv"],"backgroundTag":"invalid-boolean-style-value","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}