{"record":{"id":"585c8e11af94e80c","repo":"d2lang/d2","slug":"expected-italic-to-be-true-or-false","errorCode":null,"errorMessage":"expected \"italic\" to be true or false","messagePattern":"expected \"italic\" to be true or false","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":453,"sourceCode":"\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`)\n\t\t}\n\t\ts.Italic.Value = value\n\tcase \"underline\":\n\t\tif s.Underline == 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 \"underline\" to be true or false`)\n\t\t}\n\t\ts.Underline.Value = value\n\tcase \"filled\":\n\t\tif s.Filled == 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 \"filled\" to be true or false`)","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L435-L471","documentation":"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.","triggerScenarios":"Setting style key \"italic\" to a non-boolean value, e.g. `x.italic: yes` or `italic: slanted`.","commonSituations":"Using descriptive words like \"yes\"/\"slanted\" instead of \"true\", or interpolating config values that are not canonical boolean strings.","solutions":["Change the value to \"true\" or \"false\" (e.g. `x.italic: true`).","Use 1 or 0 as numeric boolean literals.","Remove the italic key for the default style.","Pre-validate the style value in the caller with strconv.ParseBool."],"exampleFix":"// before (D2)\nx: my shape\nx.italic: yes\n// after\nx: my shape\nx.italic: 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(italicVal) { /* 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(\"italic\", val); err != nil {\n\tif strings.Contains(err.Error(), `\"italic\" to be true or false`) {\n\t\t// fallback: default style\n\t\tval = \"false\"\n\t}\n}","preventionTips":["Use true/false or 1/0 for the italic style key.","Normalize yes/slanted inputs to booleans before applying.","Add CI validation of boolean style values.","Remove the key when default styling is fine."],"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"}