d2lang/d2 · error
no parameters in gradient
Error message
no parameters in gradient
What it means
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'.
Source
Thrown at lib/color/gradient.go:45
cssGradient = strings.TrimSpace(cssGradient)
re := regexp.MustCompile(`^(linear-gradient|radial-gradient)\((.*)\)$`)
matches := re.FindStringSubmatch(cssGradient)
if matches == nil {
return Gradient{}, errors.New("invalid gradient syntax")
}
gradientType := matches[1]
params := matches[2]
gradient := Gradient{
Type: strings.TrimSuffix(gradientType, "-gradient"),
}
paramList := splitParams(params)
if len(paramList) == 0 {
return Gradient{}, errors.New("no parameters in gradient")
}
firstParam := strings.TrimSpace(paramList[0])
if gradient.Type == "linear" && (strings.HasSuffix(firstParam, "deg") || strings.HasPrefix(firstParam, "to ")) {
gradient.Direction = firstParam
colorStops := paramList[1:]
if len(colorStops) == 0 {
return Gradient{}, errors.New("no color stops in gradient")
}
gradient.ColorStops = parseColorStops(colorStops)
} else if gradient.Type == "radial" && (firstParam == "circle" || firstParam == "ellipse") {
gradient.Direction = firstParam
colorStops := paramList[1:]
if len(colorStops) == 0 {
return Gradient{}, errors.New("no color stops in gradient")
}
gradient.ColorStops = parseColorStops(colorStops)View on GitHub (pinned to 0d69dca6f5)
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
Example fix
// before
grad, err := color.ParseGradient("linear-gradient()") // no parameters
// after
grad, err := color.ParseGradient("linear-gradient(to right, #4a90d9, #ffffff)") Defensive patterns
Strategy: validation
Validate before calling
inner := strings.SplitN(strings.TrimSuffix(strings.TrimPrefix(strings.TrimSpace(s), "linear-gradient("), ")"), ",", -1)
if len(inner) == 0 || strings.TrimSpace(inner[0]) == "" {
return errors.New("gradient requires at least one color stop")
} Type guard
func gradientHasParams(cssGradient string) bool {
open := strings.Index(cssGradient, "(")
close := strings.LastIndex(cssGradient, ")")
if open < 0 || close <= open { return false }
return strings.TrimSpace(cssGradient[open+1:close]) != ""
} Try / catch
grad, err := color.ParseGradient(input)
if err != nil && strings.Contains(err.Error(), "no parameters") {
// use a default gradient or solid fill
} Prevention
- 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
When it happens
Trigger: Calling ParseGradient with 'linear-gradient()' or 'radial-gradient()' (only whitespace inside the parens); the outer regex matches but splitParams yields zero parameters.
Common situations: 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.
Related errors
- invalid gradient syntax
- no color stops in gradient
- invalid color "%s"
- cannot parse hex color %v
- failed to unmarshal Range from %q: missing End field
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/124ecc4483cd5143.
Report an issue: GitHub.