{"record":{"id":"43eaa003db90a689","repo":"d2lang/d2","slug":"expected-shadow-to-be-true-or-false","errorCode":null,"errorMessage":"expected \"shadow\" to be true or false","messagePattern":"expected \"shadow\" to be true or false","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":383,"sourceCode":"\t\t\treturn errors.New(`expected \"stroke-dash\" to be a number between 0 and 10`)\n\t\t}\n\t\ts.StrokeDash.Value = value\n\tcase \"border-radius\":\n\t\tif s.BorderRadius == nil {\n\t\t\tbreak\n\t\t}\n\t\tf, err := strconv.Atoi(value)\n\t\tif err != nil || (f < 0) {\n\t\t\treturn errors.New(`expected \"border-radius\" to be a number greater or equal to 0`)\n\t\t}\n\t\ts.BorderRadius.Value = value\n\tcase \"shadow\":\n\t\tif s.Shadow == 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 \"shadow\" to be true or false`)\n\t\t}\n\t\ts.Shadow.Value = value\n\tcase \"3d\":\n\t\tif s.ThreeDee == 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 \"3d\" to be true or false`)\n\t\t}\n\t\ts.ThreeDee.Value = value\n\tcase \"multiple\":\n\t\tif s.Multiple == 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 \"multiple\" to be true or false`)","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L365-L401","documentation":"D2's style-setting code (SetStyle style application in d2graph) parses the \"shadow\" style value with strconv.ParseBool. If the value cannot be parsed as a boolean, this error is returned instead of setting s.Shadow.Value. Only styles whose field is non-nil (i.e., marked as set) are validated.","triggerScenarios":"Calling the style setter with style key \"shadow\" assigned a value other than strconv.ParseBool-accepted strings (\"1\", \"t\", \"T\", \"TRUE\", \"true\", \"True\", \"0\", \"f\", \"F\", \"FALSE\", \"false\", \"False\"), e.g. `x.shadow: yes` or `shadow: on` in a D2 diagram.","commonSituations":"Users writing D2 diagrams use natural-language truthy words like \"yes\", \"no\", \"on\", \"off\" or misspell \"true\"/\"false\"; also occurs when config is generated programmatically with Go boolean formatting variants not accepted by ParseBool.","solutions":["Change the shadow value to \"true\" or \"false\" (e.g. `x.shadow: true`).","If using a numeric flag, use 1 for true or 0 for false.","Remove the shadow key entirely if you only wanted the default (unset) behavior.","If generating the value in code, ensure the string is produced by strconv.FormatBool or is one of the ParseBool-accepted literals."],"exampleFix":"// before (D2)\nx: my shape\nx.shadow: yes\n// after\nx: my shape\nx.shadow: 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(shadowVal) { /* 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(\"shadow\", val); err != nil {\n\tif strings.Contains(err.Error(), `\"shadow\" to be true or false`) {\n\t\t// fall back to default or surface a friendly message\n\t\tval = \"false\"\n\t}\n}","preventionTips":["Only use true/false (or 1/0) for boolean D2 styles.","Map user-facing yes/no inputs to booleans before applying styles.","Lint diagrams with a pre-check that runs strconv.ParseBool on every boolean style key.","Remember the style is only validated when explicitly set; unset keys are silently ignored."],"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"}