{"record":{"id":"b6b31faf3795cff4","repo":"qax-os/excelize","slug":"fill-color-value-must-be-empty-or-an-array-of-one","errorCode":null,"errorMessage":"fill color value must be empty or an array of one color for 'pattern' type","messagePattern":"fill color value must be empty or an array of one color for 'pattern' type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":74,"sourceCode":"\t// ErrDefinedNameScope defined the error message on not found defined name\n\t// in the given scope.\n\tErrDefinedNameScope = errors.New(\"no defined name on the scope\")\n\t// ErrExistsSheet defined the error message on given sheet already exists.\n\tErrExistsSheet = errors.New(\"the same name sheet already exists\")\n\t// ErrExistsTableName defined the error message on given table already\n\t// exists.\n\tErrExistsTableName = errors.New(\"the same name table already exists\")\n\t// ErrFillType defined the error message on receive an invalid fill type.\n\tErrFillType = errors.New(\"fill type value must be one of 'gradient' or 'pattern'\")\n\t// ErrFillGradientColor defined the error message on receive an invalid fill\n\t// color for 'gradient' type.\n\tErrFillGradientColor = errors.New(\"fill color value must be an array of two colors for 'gradient' type\")\n\t// ErrFillGradientShading defined the error message on receive an invalid\n\t// fill shading for 'gradient' type.\n\tErrFillGradientShading = errors.New(\"fill shading value must be between 0 and 16 for 'gradient' type\")\n\t// ErrFillPatternColor defined the error message on receive an invalid fill\n\t// color for 'pattern' type.\n\tErrFillPatternColor = errors.New(\"fill color value must be empty or an array of one color for 'pattern' type\")\n\t// ErrFillPattern defined the error message on receive an invalid fill\n\t// pattern.\n\tErrFillPattern = errors.New(\"fill pattern value must be between 0 and 18\")\n\t// ErrFontLength defined the error message on the length of the font\n\t// family name overflow.\n\tErrFontLength = fmt.Errorf(\"the length of the font family name must be less than or equal to %d\", MaxFontFamilyLength)\n\t// ErrFontSize defined the error message on the size of the font is invalid.\n\tErrFontSize = fmt.Errorf(\"font size must be an integer from %d to %d points\", MinFontSize, MaxFontSize)\n\t// ErrFormControlValue defined the error message for receiving a scroll\n\t// value exceeds limit.\n\tErrFormControlValue = fmt.Errorf(\"scroll value must be an integer from 0 to %d\", MaxFormControlValue)\n\t// ErrGroupSheets defined the error message on group sheets.\n\tErrGroupSheets = errors.New(\"group worksheet must contain an active worksheet\")\n\t// ErrImgExt defined the error message on receive an unsupported image\n\t// extension.\n\tErrImgExt = errors.New(\"unsupported image extension\")\n\t// ErrInvalidFormula defined the error message on receive an invalid\n\t// formula.","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L56-L92","documentation":"ErrFillPatternColor is returned by parseFormatStyleSet when Fill.Type is \"pattern\" and Fill.Color contains more than one color string. Pattern fills accept either no color (empty slice) or exactly one foreground color.","triggerScenarios":"Calling f.NewStyle(&Style{Fill: Fill{Type: \"pattern\", Color: []string{\"FFFFFF\", \"4E71BE\"}}}) with two or more colors.","commonSituations":"Reusing the same two-element Color slice built for a gradient fill when switching the fill type to \"pattern\", or merging multiple configured colors into one slice.","solutions":["Trim Fill.Color to at most one entry for pattern fills.","If you need two colors, keep Fill.Type as \"gradient\" instead of \"pattern\".","Validate len(style.Fill.Color) <= 1 before calling NewStyle."],"exampleFix":"// before\nf.NewStyle(&Style{Fill: Fill{Type: \"pattern\", Color: []string{\"FFFFFF\", \"4E71BE\"}}})\n// after\nf.NewStyle(&Style{Fill: Fill{Type: \"pattern\", Color: []string{\"FFFF00\"}, Pattern: 1}})","handlingStrategy":"validation","validationCode":"if fill.Type == \"pattern\" && len(fill.Color) > 1 {\n    return errors.New(\"pattern fill accepts at most one color\")\n}","typeGuard":"func hasAtMostOneColor(c []string) bool { return len(c) <= 1 }","tryCatchPattern":"_, err := f.NewStyle(&Style{Fill: fill})\nif errors.Is(err, excelize.ErrFillPatternColor) {\n    fill.Color = fill.Color[:1] // keep first color only\n    _, err = f.NewStyle(&Style{Fill: fill})\n}","preventionTips":["Never reuse gradient color slices for pattern fills.","Normalize color slices in a helper before calling NewStyle.","Keep a single source of truth for fill configuration per style."],"tags":["go","excelize","style","pattern","validation"],"backgroundTag":"invalid-array-length","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}