{"record":{"id":"3f36055ae1ab12ab","repo":"qax-os/excelize","slug":"fill-color-value-must-be-an-array-of-two-colors-fo","errorCode":null,"errorMessage":"fill color value must be an array of two colors for 'gradient' type","messagePattern":"fill color value must be an array of two colors for 'gradient' type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":68,"sourceCode":"\t// ErrDataValidationRange defined the error message on set decimal range\n\t// exceeds limit.\n\tErrDataValidationRange = errors.New(\"data validation range exceeds limit\")\n\t// ErrDefinedNameDuplicate defined the error message on the same name\n\t// already exists on the scope.\n\tErrDefinedNameDuplicate = errors.New(\"the same name already exists on the scope\")\n\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.","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L50-L86","documentation":"ErrFillGradientColor is returned by parseFormatStyleSet when Fill.Type is \"gradient\" but Fill.Color does not contain exactly two color strings. Gradient fills in this library are two-stop gradients, so the Color slice must be a two-element array.","triggerScenarios":"Calling f.NewStyle(&Style{Fill: Fill{Type: \"gradient\", Color: []string{\"FFFFFF\"}, Shading: 0}}) with one color, three colors, or no colors at all.","commonSituations":"Assuming gradient works like pattern fill (which takes 0 or 1 color), building the color list programmatically and ending up with a single entry, or forgetting to set Color entirely.","solutions":["Provide exactly two color strings in Fill.Color, e.g. []string{\"FFFFFF\", \"4E71BE\"}.","If you only have one color, switch Fill.Type to \"pattern\" instead of \"gradient\".","Validate len(style.Fill.Color) == 2 before calling NewStyle."],"exampleFix":"// before\nf.NewStyle(&Style{Fill: Fill{Type: \"gradient\", Color: []string{\"FFFFFF\"}, Shading: 0}})\n// after\nf.NewStyle(&Style{Fill: Fill{Type: \"gradient\", Color: []string{\"FFFFFF\", \"4E71BE\"}, Shading: 0}})","handlingStrategy":"validation","validationCode":"if fill.Type == \"gradient\" && len(fill.Color) != 2 {\n    return errors.New(\"gradient fill requires exactly two colors\")\n}","typeGuard":"func isTwoColorSlice(c []string) bool { return len(c) == 2 }","tryCatchPattern":"_, err := f.NewStyle(&Style{Fill: fill})\nif errors.Is(err, excelize.ErrFillGradientColor) {\n    fill.Color = append(fill.Color, \"FFFFFF\") // or fix input\n}","preventionTips":["Always construct gradient colors as a literal two-element slice.","Centralize fill construction in a helper that enforces the color count.","Switch to pattern fill when only one color is needed."],"tags":["go","excelize","style","gradient","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"}