{"record":{"id":"ae9536e98e623001","repo":"d2lang/d2","slug":"expected-font-size-to-be-a-number-between-8-and","errorCode":null,"errorMessage":"expected \"font-size\" to be a number between 8 and 100","messagePattern":"expected \"font-size\" to be a number between 8 and 100","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":418,"sourceCode":"\t\tif err != nil {\n\t\t\treturn errors.New(`expected \"multiple\" to be true or false`)\n\t\t}\n\t\ts.Multiple.Value = value\n\tcase \"font\":\n\t\tif s.Font == nil {\n\t\t\tbreak\n\t\t}\n\t\tif _, ok := d2fonts.D2_FONT_TO_FAMILY[strings.ToLower(value)]; !ok {\n\t\t\treturn fmt.Errorf(`\"%v\" is not a valid font in our system`, value)\n\t\t}\n\t\ts.Font.Value = strings.ToLower(value)\n\tcase \"font-size\":\n\t\tif s.FontSize == nil {\n\t\t\tbreak\n\t\t}\n\t\tf, err := strconv.Atoi(value)\n\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}","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L400-L436","documentation":"D2 validates the \"font-size\" style by parsing it as an integer and requiring it to be between 8 and 100 inclusive. A value that is not an integer, or outside that range, returns this error and the style is rejected.","triggerScenarios":"Setting style key \"font-size\" to a non-integer string (e.g. \"12.5\", \"big\") or an integer below 8 or above 100 (e.g. `x.font-size: 150`).","commonSituations":"Users request large headline text beyond the cap (e.g. 200), use pixel units like \"14px\", or decimals like \"12.5\" copied from CSS.","solutions":["Use an integer between 8 and 100 (e.g. `x.font-size: 24`).","Remove units like \"px\" or \"em\" from the value.","Clamp generated values in code: if f < 8 { f = 8 }; if f > 100 { f = 100 }.","For larger text, use container/scale options instead of exceeding the font-size cap."],"exampleFix":"// before (D2)\nx: my shape\nx.font-size: 150\n// after\nx: my shape\nx.font-size: 100","handlingStrategy":"validation","validationCode":"func validFontSize(v string) (string, bool) {\n\tf, err := strconv.Atoi(v)\n\tif err != nil || f < 8 || f > 100 {\n\t\treturn \"\", false\n\t}\n\treturn v, true\n}\n// before applying: fs, ok := validFontSize(val); if !ok { fs = strconv.Itoa(clamp) }","typeGuard":"func isFontSizeInRange(v string) bool {\n\tf, err := strconv.Atoi(v)\n\treturn err == nil && f >= 8 && f <= 100\n}","tryCatchPattern":"if err := obj.SetStyle(\"font-size\", val); err != nil {\n\tif strings.Contains(err.Error(), `\"font-size\" to be a number between 8 and 100`) {\n\t\t// fallback to a safe default\n\t\tval = \"16\"\n\t}\n}","preventionTips":["Keep font-size an integer within 8–100.","Strip units (px/em/rem) from user input before applying.","Clamp values in code instead of passing them raw.","Reject decimals (12.5) early — Atoi does not parse floats."],"tags":["d2","style-validation","font-size","range-check"],"backgroundTag":"style-value-out-of-range","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}