{"record":{"id":"70e580b8b607ebdc","repo":"d2lang/d2","slug":"expected-stroke-dash-to-be-a-number-between-0-an","errorCode":null,"errorMessage":"expected \"stroke-dash\" to be a number between 0 and 10","messagePattern":"expected \"stroke-dash\" to be a number between 0 and 10","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":365,"sourceCode":"\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`)\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`)","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L347-L383","documentation":"The 'stroke-dash' style key must parse as an integer between 0 and 10 inclusive. This error is returned when strconv.Atoi fails or the value falls outside 0–10.","triggerScenarios":"Setting style 'stroke-dash' to a non-integer (\"dashed\", \"1.5\") or out-of-range integer (e.g. 12, -3).","commonSituations":"D2 authors trying CSS dash-style keywords or picking dash sizes above the allowed maximum.","solutions":["Use an integer from 0 to 10 for stroke-dash.","Replace keyword values like \"dashed\" with the numeric equivalent.","Clamp values above 10 down to 10."],"exampleFix":"// before\nx.style.stroke-dash: dashed\n// after\nx.style.stroke-dash: 4","handlingStrategy":"validation","validationCode":"n, err := strconv.Atoi(v)\nif err != nil || n < 0 || n > 10 {\n    return fmt.Errorf(\"stroke-dash %q must be an integer 0-10\", v)\n}","typeGuard":"func validStrokeDash(s string) bool { n, err := strconv.Atoi(s); return err == nil && n >= 0 && n <= 10 }","tryCatchPattern":"if err := applyStyle(\"stroke-dash\", value); err != nil {\n    if strings.Contains(err.Error(), \"stroke-dash\") {\n        value = \"0\" // solid line default\n    }\n}","preventionTips":["Use numeric dash values 0–10, not CSS keywords.","Clamp before assigning to StrokeDash.Value.","Document the 0–10 limit wherever users input dash styles."],"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"}