{"record":{"id":"53993d06be0a0977","repo":"d2lang/d2","slug":"expected-stroke-width-to-be-a-number-between-0-a","errorCode":null,"errorMessage":"expected \"stroke-width\" to be a number between 0 and 15","messagePattern":"expected \"stroke-width\" to be a number between 0 and 15","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":356,"sourceCode":"\t\tif !color.ValidColor(value) {\n\t\t\treturn errors.New(`expected \"fill\" to be a valid named color (\"orange\"), a hex code (\"#f0ff3a\"), or a gradient (\"linear-gradient(red, blue)\")`)\n\t\t}\n\t\ts.Fill.Value = value\n\tcase \"fill-pattern\":\n\t\tif s.FillPattern == nil {\n\t\t\tbreak\n\t\t}\n\t\tif !go2.Contains(d2ast.FillPatterns, strings.ToLower(value)) {\n\t\t\treturn fmt.Errorf(`expected \"fill-pattern\" to be one of: %s`, strings.Join(d2ast.FillPatterns, \", \"))\n\t\t}\n\t\ts.FillPattern.Value = value\n\tcase \"stroke-width\":\n\t\tif s.StrokeWidth == nil {\n\t\t\tbreak\n\t\t}\n\t\tf, err := strconv.Atoi(value)\n\t\tif err != nil || (f < 0 || f > 15) {\n\t\t\treturn errors.New(`expected \"stroke-width\" to be a number between 0 and 15`)\n\t\t}\n\t\ts.StrokeWidth.Value = value\n\tcase \"stroke-dash\":\n\t\tif s.StrokeDash == nil {\n\t\t\tbreak\n\t\t}\n\t\tf, err := strconv.Atoi(value)\n\t\tif err != nil || (f < 0 || f > 10) {\n\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`)","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L338-L374","documentation":"The 'stroke-width' style key must parse as an integer between 0 and 15 inclusive. This error is returned when strconv.Atoi fails or the value is out of that range.","triggerScenarios":"Setting style 'stroke-width' to a non-integer (\"2.5\", \"thick\") or an integer outside 0–15 (e.g. 20, -1).","commonSituations":"D2 authors assuming pixel-scale widths larger than 15 are allowed, or using decimals/units like \"2px\".","solutions":["Set stroke-width to an integer from 0 to 15.","Remove units like \"px\" and round decimals to integers.","Clamp large values to 15 before applying."],"exampleFix":"// before\nx.style.stroke-width: 2.5\n// after\nx.style.stroke-width: 2","handlingStrategy":"validation","validationCode":"n, err := strconv.Atoi(v)\nif err != nil || n < 0 || n > 15 {\n    return fmt.Errorf(\"stroke-width %q must be an integer 0-15\", v)\n}","typeGuard":"func validStrokeWidth(s string) bool { n, err := strconv.Atoi(s); return err == nil && n >= 0 && n <= 15 }","tryCatchPattern":"if err := applyStyle(\"stroke-width\", value); err != nil {\n    if strings.Contains(err.Error(), \"stroke-width\") {\n        value = \"1\" // safe default\n    }\n}","preventionTips":["Clamp stroke-width inputs to [0,15] before applying.","Reject decimals and unit suffixes early.","Mirror the exact d2graph validation in your own form/input validation."],"tags":["validation","d2graph","numeric","style"],"backgroundTag":"invalid-style-value","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}