The operation was attempted past the valid range
Indicates an operation attempted to access data past a valid range, such as seeking past the end of a file. This is a client-side error.
- 1Requesting a page of results that is beyond the total number of pages (e.g., page 11 of 10).
- 2Seeking or reading past the end of a file or data stream.
- 3Accessing an array index that is out of bounds on the server.
A client requests page 100 of a paginated list that only has 10 pages.
// Client requests a page number that doesn't exist
try {
// There are only 50 results, so page 6 (at 10 per page) is out of range.
await client.listItems({ page: 6, pageSize: 10 });
} catch (e) {
// e.code will be OUT_OF_RANGE
}expected output
StatusCode.OUT_OF_RANGE: The operation was attempted past the valid range
Fix 1
Validate Client-Side Pagination/Index Values
WHEN Before making a request for a specific page or index.
// Client gets total number of items first
const metadata = await client.listItems({ page: 1, pageSize: 1 });
const totalPages = Math.ceil(metadata.totalItems / pageSize);
if (requestedPage > totalPages) {
showError("Invalid page number.");
}Why this works
Determine the valid range from the server before attempting to access a specific point within it.
Fix 2
Handle the Error Gracefully
WHEN When reaching the end of a list.
// When loading more items in an infinite scroll
try {
const newItems = await client.listItems({ page: currentPage });
addItemsToView(newItems);
} catch (e) {
if (e.code === grpc.status.OUT_OF_RANGE) {
// This is expected, it just means we're at the end.
disableInfiniteScroll();
}
}Why this works
Treating OUT_OF_RANGE as a signal to stop paginating is a common and correct pattern.
✕ Retry the request without changing the index or page number
This is a deterministic error. The requested range is invalid and will remain invalid unless the client corrects it.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev