{"record":{"id":"4319e6d3fd76f699","repo":"qax-os/excelize","slug":"fill-shading-value-must-be-between-0-and-16-for-g","errorCode":null,"errorMessage":"fill shading value must be between 0 and 16 for 'gradient' type","messagePattern":"fill shading value must be between 0 and 16 for 'gradient' type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":71,"sourceCode":"\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.\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.","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L53-L89","documentation":"ErrFillGradientShading is returned by parseFormatStyleSet when Fill.Type is \"gradient\" and Fill.Shading is outside the inclusive range 0-16. The shading value controls the gradient direction/variant and must be a valid OOXML shading enum.","triggerScenarios":"Calling f.NewStyle(&Style{Fill: Fill{Type: \"gradient\", Color: []string{\"FFFFFF\", \"4E71BE\"}, Shading: 17}}) or with a negative Shading value.","commonSituations":"Computing shading from user input without range checking, using arbitrary constants, or off-by-one errors when the valid maximum is 16.","solutions":["Set Fill.Shading to a value between 0 and 16 inclusive (e.g. 1 for horizontal).","Clamp the value: if Shading > 16 { Shading = 16 }; if Shading < 0 { Shading = 0 } before calling NewStyle.","Validate the range in your own code before constructing the Style."],"exampleFix":"// before\nf.NewStyle(&Style{Fill: Fill{Type: \"gradient\", Color: colors, Shading: 17}})\n// after\nshading := 17\nif shading > 16 { shading = 16 }\nf.NewStyle(&Style{Fill: Fill{Type: \"gradient\", Color: colors, Shading: shading}})","handlingStrategy":"validation","validationCode":"if fill.Type == \"gradient\" && (fill.Shading < 0 || fill.Shading > 16) {\n    return fmt.Errorf(\"shading %d out of range 0-16\", fill.Shading)\n}","typeGuard":"func validShading(s int) bool { return s >= 0 && s <= 16 }","tryCatchPattern":"_, err := f.NewStyle(&Style{Fill: fill})\nif errors.Is(err, excelize.ErrFillGradientShading) {\n    fill.Shading = 1 // safe default\n    _, err = f.NewStyle(&Style{Fill: fill})\n}","preventionTips":["Clamp user-supplied shading values to [0, 16] at input time.","Use named constants for the shading variants instead of raw ints.","Add a unit test covering boundary values 0, 16, and 17."],"tags":["go","excelize","style","gradient","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}