d2lang/d2 · error

expected "fill-pattern" to be one of: %s

Error message

expected "fill-pattern" to be one of: %s

What it means

The 'fill-pattern' style key must be one of the values in d2ast.FillPatterns (case-insensitive match after strings.ToLower). This error lists the allowed values when the provided value isn't one of them.

Source

Thrown at d2graph/d2graph.go:347

		}
		if !color.ValidColor(value) {
			return errors.New(`expected "stroke" to be a valid named color ("orange"), a hex code ("#f0ff3a"), or a gradient ("linear-gradient(red, blue)")`)
		}
		s.Stroke.Value = value
	case "fill":
		if s.Fill == nil {
			break
		}
		if !color.ValidColor(value) {
			return errors.New(`expected "fill" to be a valid named color ("orange"), a hex code ("#f0ff3a"), or a gradient ("linear-gradient(red, blue)")`)
		}
		s.Fill.Value = value
	case "fill-pattern":
		if s.FillPattern == nil {
			break
		}
		if !go2.Contains(d2ast.FillPatterns, strings.ToLower(value)) {
			return fmt.Errorf(`expected "fill-pattern" to be one of: %s`, strings.Join(d2ast.FillPatterns, ", "))
		}
		s.FillPattern.Value = value
	case "stroke-width":
		if s.StrokeWidth == nil {
			break
		}
		f, err := strconv.Atoi(value)
		if err != nil || (f < 0 || f > 15) {
			return errors.New(`expected "stroke-width" to be a number between 0 and 15`)
		}
		s.StrokeWidth.Value = value
	case "stroke-dash":
		if s.StrokeDash == nil {
			break
		}
		f, err := strconv.Atoi(value)
		if err != nil || (f < 0 || f > 10) {
			return errors.New(`expected "stroke-dash" to be a number between 0 and 10`)

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Use one of the values listed in the error message (strings.Join(d2ast.FillPatterns, ", ")).
  2. Check the exact spelling against d2ast.FillPatterns in d2ast.
  3. Remove the fill-pattern key if no pattern is desired.

Example fix

// before
x.style.fill-pattern: hatch
// after
x.style.fill-pattern: dots
Defensive patterns

Strategy: validation

Validate before calling

if !go2.Contains(d2ast.FillPatterns, strings.ToLower(v)) {
    return fmt.Errorf("fill-pattern %q must be one of: %s", v, strings.Join(d2ast.FillPatterns, ", "))
}

Type guard

func validFillPattern(v string) bool { return go2.Contains(d2ast.FillPatterns, strings.ToLower(v)) }

Try / catch

if err := applyStyle("fill-pattern", value); err != nil {
    if strings.Contains(err.Error(), "fill-pattern") {
        value = d2ast.FillPatterns[0] // default pattern
    }
}

Prevention

When it happens

Trigger: Setting style 'fill-pattern' to anything not in d2ast.FillPatterns, e.g. `fill-pattern: hatch` or `fill-pattern: dotted` if not in the list.

Common situations: D2 authors guessing pattern names or copying SVG pattern names instead of the D2-recognized ones (e.g. "dots", "lines", "grid" — whichever d2ast.FillPatterns contains).

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/c2fba13585c5434e. Report an issue: GitHub.