{"record":{"id":"d4205a39d5fa32cc","repo":"qax-os/excelize","slug":"errsparklinelocation","errorCode":"ErrSparklineLocation","errorMessage":"parameter 'Location' is required","messagePattern":"parameter 'Location' is required","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":161,"sourceCode":"\tErrSheetIdx = errors.New(\"invalid worksheet index\")\n\t// ErrSheetNameBlank defined the error message on receive the blank sheet\n\t// name.\n\tErrSheetNameBlank = errors.New(\"the sheet name can not be blank\")\n\t// ErrSheetNameInvalid defined the error message on receive the sheet name\n\t// contains invalid characters.\n\tErrSheetNameInvalid = errors.New(\"the sheet can not contain any of the characters :\\\\/?*[or]\")\n\t// ErrSheetNameLength defined the error message on receiving the sheet\n\t// name length exceeds the limit.\n\tErrSheetNameLength = fmt.Errorf(\"the sheet name length exceeds the %d characters limit\", MaxSheetNameLength)\n\t// ErrSheetNameSingleQuote defined the error message on the first or last\n\t// character of the sheet name was a single quote.\n\tErrSheetNameSingleQuote = errors.New(\"the first or last character of the sheet name can not be a single quote\")\n\t// ErrSparkline defined the error message on receive the invalid sparkline\n\t// parameters.\n\tErrSparkline = errors.New(\"must have the same number of 'Location' and 'Range' parameters\")\n\t// ErrSparklineLocation defined the error message on missing Location\n\t// parameters\n\tErrSparklineLocation = errors.New(\"parameter 'Location' is required\")\n\t// ErrSparklineRange defined the error message on missing sparkline Range\n\t// parameters\n\tErrSparklineRange = errors.New(\"parameter 'Range' is required\")\n\t// ErrSparklineStyle defined the error message on receive the invalid\n\t// sparkline Style parameters.\n\tErrSparklineStyle = errors.New(\"parameter 'Style' value must be an integer from 0 to 35\")\n\t// ErrSparklineType defined the error message on receive the invalid\n\t// sparkline Type parameters.\n\tErrSparklineType = errors.New(\"parameter 'Type' value must be one of 'line', 'column' or 'win_loss'\")\n\t// ErrTotalSheetHyperlinks defined the error message on hyperlinks count\n\t// overflow.\n\tErrTotalSheetHyperlinks = errors.New(\"over maximum limit hyperlinks in a worksheet\")\n\t// ErrTransparency defined the error message for receiving a transparency\n\t// value exceeds limit.\n\tErrTransparency = errors.New(\"transparency value must be an integer from 0 to 100\")\n\t// ErrUnknownEncryptMechanism defined the error message on unsupported\n\t// encryption mechanism.\n\tErrUnknownEncryptMechanism = errors.New(\"unknown encryption mechanism\")","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L143-L179","documentation":"Sentinel error ErrSparklineLocation returned by AddSparkline when the SparklineOptions.Location parameter is empty or omitted. It fires as a validation guard before any worksheet modification: a sparkline must have at least one cell location to anchor it, so callers adding a sparkline without setting Location get this error and the workbook is left unchanged.","triggerScenarios":"Calling f.AddSparkline(\"Sheet1\", &SparklineOptions{Range: []string{\"Sheet2!A3:E3\"}}) with no Location field set, via parseFormatAddSparklineSet.","commonSituations":"Constructing SparklineOptions dynamically and forgetting Location; copying a struct literal from a Range-only example; unmarshaling options from JSON where the field is missing.","solutions":["Set opts.Location to at least one cell reference (e.g. []string{\"F3\"}) before calling AddSparkline","Validate len(opts.Location) >= 1 in your options builder","Provide both Location and Range together when constructing options"],"exampleFix":"// before\nf.AddSparkline(\"Sheet1\", &SparklineOptions{Range: []string{\"Sheet2!A3:E3\"}})\n// after\nf.AddSparkline(\"Sheet1\", &SparklineOptions{Location: []string{\"F3\"}, Range: []string{\"Sheet2!A3:E3\"}})","handlingStrategy":"validation","validationCode":"if len(opts.Location) < 1 {\n    return errors.New(\"SparklineOptions.Location is required\")\n}","typeGuard":"func sparklineOptsValid(o *excelize.SparklineOptions) bool {\n    return len(o.Location) > 0 && len(o.Location) == len(o.Range)\n}","tryCatchPattern":"if err := f.AddSparkline(\"Sheet1\", opts); err != nil {\n    if errors.Is(err, excelize.ErrSparklineLocation) {\n        // add a Location before retrying\n    }\n    return err\n}","preventionTips":["Always set Location together with Range in SparklineOptions literals","Validate options structs at construction, not at call time","Cover required-field cases in unit tests"],"tags":["go","excelize","sparkline","validation"],"backgroundTag":"sparkline-parameter-missing","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}