qax-os/excelize · error
coordinates length must be 4
Error message
coordinates length must be 4
What it means
ErrCoordinates is returned when a coordinates tuple does not contain exactly 4 integers. Functions like sortCoordinates and coordinatesToRangeRef expect [col1,row1,col2,row2] defining a rectangular range; any other length cannot form a range reference. It is a fast input-shape check.
Source
Thrown at errors.go:43
// boolean type XML attribute.
ErrAttrValBool = errors.New("unexpected child of attrValBool")
// ErrCellCharsLength defined the error message for receiving a cell
// characters length that exceeds the limit.
ErrCellCharsLength = fmt.Errorf("cell value must be 0-%d characters", TotalCellChars)
// ErrCellStyles defined the error message on cell styles exceeds the limit.
ErrCellStyles = fmt.Errorf("the cell styles exceeds the %d limit", MaxCellStyles)
// ErrChartTitle defined the error message on both formula and rich text for
// chart title.
ErrChartTitle = errors.New("cannot set both 'Formula' and 'Paragraph' for chart title")
// ErrColumnNumber defined the error message on receive an invalid column
// number.
ErrColumnNumber = fmt.Errorf("the column number must be greater than or equal to %d and less than or equal to %d", MinColumns, MaxColumns)
// ErrColumnWidth defined the error message on receive an invalid column
// width.
ErrColumnWidth = fmt.Errorf("the width of the column must be less than or equal to %d characters", MaxColumnWidth)
// ErrCoordinates defined the error message on invalid coordinates tuples
// length.
ErrCoordinates = errors.New("coordinates length must be 4")
// ErrCustomNumFmt defined the error message on receive the empty custom
// number format.
ErrCustomNumFmt = errors.New("custom number format can not be empty")
// ErrDataValidationFormulaLength defined the error message for receiving a
// data validation formula length that exceeds the limit.
ErrDataValidationFormulaLength = fmt.Errorf("data validation must be 0-%d characters", MaxFieldLength)
// ErrDataValidationRange defined the error message on set decimal range
// exceeds limit.
ErrDataValidationRange = errors.New("data validation range exceeds limit")
// ErrDefinedNameDuplicate defined the error message on the same name
// already exists on the scope.
ErrDefinedNameDuplicate = errors.New("the same name already exists on the scope")
// ErrDefinedNameScope defined the error message on not found defined name
// in the given scope.
ErrDefinedNameScope = errors.New("no defined name on the scope")
// ErrExistsSheet defined the error message on given sheet already exists.
ErrExistsSheet = errors.New("the same name sheet already exists")
// ErrExistsTableName defined the error message on given table alreadyView on GitHub (pinned to f2483381fb)
Solutions
- Ensure the slice has exactly 4 elements: [col1, row1, col2, row2]
- Use CoordinatesToCellName twice and join with ":" if you only have two individual cells
- Add a length check (len(c) == 4) before calling and produce a domain-specific error
- Remember coordinates are 1-based row and 0-based/1-based per API docs — verify ordering col,row,col,row
Example fix
// before
ref, err := f.coordinatesToRangeRef([]int{1, 1, 5}) // ErrCoordinates
// after
ref, err := f.coordinatesToRangeRef([]int{1, 1, 5, 10}) // "B1:F10"-style range Defensive patterns
Strategy: type-guard
Validate before calling
func validRange(c []int) bool { return len(c) == 4 } Type guard
func isRangeCoordinates(c []int) bool {
return len(c) == 4 && c[0] >= 1 && c[2] >= 1
} Prevention
- Always build range slices as [col1,row1,col2,row2]
- Use a constructor/helper instead of literal slices at call sites
- Distinguish 2-int cell coordinates from 4-int range coordinates in your types
When it happens
Trigger: Calling coordinatesToRangeRef or sortCoordinates with slices of length 0, 2, 3, 5+ instead of exactly 4; passing a two-cell pair [col1,row1,col2,row2] misremembered as two separate args or as [x1,y1,x2,y2] of wrong arity.
Common situations: Building ranges from user input or CLI flags where some values were dropped; appending coordinates in a loop but forgetting the end cell; confusing cell coordinates (2 ints) with range coordinates (4 ints).
Related errors
- invalid reference
- ErrSparklineStyle
- ErrTransparency
- cannot convert cell %q to coordinates: %v
- invalid cell reference [%d, %d]
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/6a2552a51c20dde3.
Report an issue: GitHub.