{"record":{"id":"715085667cf2ce9a","repo":"qax-os/excelize","slug":"errsparkline","errorCode":"ErrSparkline","errorMessage":"must have the same number of 'Location' and 'Range' parameters","messagePattern":"must have the same number of 'Location' and 'Range' parameters","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":158,"sourceCode":"\tErrSave = errors.New(\"no path defined for file, consider File.WriteTo or File.Write\")\n\t// ErrSheetIdx defined the error message on receive the invalid worksheet\n\t// index.\n\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\")","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L140-L176","documentation":"Sentinel error ErrSparklineLocation returned by AddSparkline when the SparklineOptions.Location slice is empty; the guard `len(opts.Location) < 1` fires before any worksheet mutation, meaning no sparkline anchor cells were supplied.","triggerScenarios":"Calling f.AddSparkline(\"Sheet1\", &SparklineOptions{Location: [\"F3\"], Range: [\"A1:E1\",\"A2:E2\"]}) or any mismatch of len(Location) vs len(Range), via parseFormatAddSparklineSet in sparkline.go.","commonSituations":"Building sparkline options from loops or config where locations and ranges are collected separately and drift out of sync; multi-sparkline calls where one list got an extra entry.","solutions":["Ensure len(opts.Location) == len(opts.Range) before calling AddSparkline","Build both slices in the same loop so they stay paired","Use the min length of both slices or reject the input early"],"exampleFix":"// before\nopts := &SparklineOptions{Location: []string{\"F3\"}, Range: []string{\"A1:E1\", \"A2:E2\"}}\nf.AddSparkline(\"Sheet1\", opts)\n// after\nif len(opts.Location) != len(opts.Range) {\n    return errors.New(\"Location and Range must have equal length\")\n}\nf.AddSparkline(\"Sheet1\", opts)","handlingStrategy":"validation","validationCode":"if len(opts.Location) != len(opts.Range) {\n    return fmt.Errorf(\"Location (%d) and Range (%d) counts differ\", len(opts.Location), len(opts.Range))\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.ErrSparkline) {\n        // rebalance Location/Range slices\n    }\n    return err\n}","preventionTips":["Build Location and Range in the same loop so they stay paired","Assert equal lengths in tests that construct sparkline options","Store sparkline definitions as pairs, not separate lists"],"tags":["go","excelize","sparkline","validation"],"backgroundTag":"sparkline-parameter-mismatch","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}