OUT_OF_RANGE
gRPCERRORCommonClient-SideHIGH confidence

The operation was attempted past the valid range

What this means

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.

Why it happens
  1. 1Requesting a page of results that is beyond the total number of pages (e.g., page 11 of 10).
  2. 2Seeking or reading past the end of a file or data stream.
  3. 3Accessing an array index that is out of bounds on the server.
How to reproduce

A client requests page 100 of a paginated list that only has 10 pages.

trigger — this will error
trigger — this will error
// 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.

Validate Client-Side Pagination/Index Values
// 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.

Handle the Error Gracefully
// 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.

What not to do

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.

Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All gRPC errors