{"record":{"id":"124ecc4483cd5143","repo":"d2lang/d2","slug":"no-parameters-in-gradient","errorCode":null,"errorMessage":"no parameters in gradient","messagePattern":"no parameters in gradient","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/color/gradient.go","lineNumber":45,"sourceCode":"\tcssGradient = strings.TrimSpace(cssGradient)\n\n\tre := regexp.MustCompile(`^(linear-gradient|radial-gradient)\\((.*)\\)$`)\n\tmatches := re.FindStringSubmatch(cssGradient)\n\tif matches == nil {\n\t\treturn Gradient{}, errors.New(\"invalid gradient syntax\")\n\t}\n\n\tgradientType := matches[1]\n\tparams := matches[2]\n\n\tgradient := Gradient{\n\t\tType: strings.TrimSuffix(gradientType, \"-gradient\"),\n\t}\n\n\tparamList := splitParams(params)\n\n\tif len(paramList) == 0 {\n\t\treturn Gradient{}, errors.New(\"no parameters in gradient\")\n\t}\n\n\tfirstParam := strings.TrimSpace(paramList[0])\n\n\tif gradient.Type == \"linear\" && (strings.HasSuffix(firstParam, \"deg\") || strings.HasPrefix(firstParam, \"to \")) {\n\t\tgradient.Direction = firstParam\n\t\tcolorStops := paramList[1:]\n\t\tif len(colorStops) == 0 {\n\t\t\treturn Gradient{}, errors.New(\"no color stops in gradient\")\n\t\t}\n\t\tgradient.ColorStops = parseColorStops(colorStops)\n\t} else if gradient.Type == \"radial\" && (firstParam == \"circle\" || firstParam == \"ellipse\") {\n\t\tgradient.Direction = firstParam\n\t\tcolorStops := paramList[1:]\n\t\tif len(colorStops) == 0 {\n\t\t\treturn Gradient{}, errors.New(\"no color stops in gradient\")\n\t\t}\n\t\tgradient.ColorStops = parseColorStops(colorStops)","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/lib/color/gradient.go#L27-L63","documentation":"After matching the gradient function wrapper, ParseGradient splits the inner parameter list. If the parameter list is empty (nothing between the parentheses), there is no color or direction to build a Gradient from, so it returns 'no parameters in gradient'.","triggerScenarios":"Calling ParseGradient with 'linear-gradient()' or 'radial-gradient()' (only whitespace inside the parens); the outer regex matches but splitParams yields zero parameters.","commonSituations":"Style values left as placeholder gradients in templates; templating/engine code that interpolates an empty color variable between the parentheses; users typing the gradient function without any colors.","solutions":["Provide at least one (ideally two or more) color stops inside the gradient parentheses","Validate gradient input non-empty between parens before calling ParseGradient","Add a fallback solid color when the gradient parameter list is empty"],"exampleFix":"// before\ngrad, err := color.ParseGradient(\"linear-gradient()\") // no parameters\n// after\ngrad, err := color.ParseGradient(\"linear-gradient(to right, #4a90d9, #ffffff)\")","handlingStrategy":"validation","validationCode":"inner := strings.SplitN(strings.TrimSuffix(strings.TrimPrefix(strings.TrimSpace(s), \"linear-gradient(\"), \")\"), \",\", -1)\nif len(inner) == 0 || strings.TrimSpace(inner[0]) == \"\" {\n    return errors.New(\"gradient requires at least one color stop\")\n}","typeGuard":"func gradientHasParams(cssGradient string) bool {\n    open := strings.Index(cssGradient, \"(\")\n    close := strings.LastIndex(cssGradient, \")\")\n    if open < 0 || close <= open { return false }\n    return strings.TrimSpace(cssGradient[open+1:close]) != \"\"\n}","tryCatchPattern":"grad, err := color.ParseGradient(input)\nif err != nil && strings.Contains(err.Error(), \"no parameters\") {\n    // use a default gradient or solid fill\n}","preventionTips":["Never interpolate empty template variables into gradient parens","Require at least two color stops when authoring gradients","Validate rendered style strings before applying them to a diagram"],"tags":["color","gradient","parsing"],"backgroundTag":"invalid-gradient-syntax","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}