gatsbyjs/gatsby · error · Error

Both arguments must not be negative and end must be greater

Error message

Both arguments must not be negative and end must be greater than start

What it means

GatsbyIterable.slice validates its bounds like Array.prototype.slice: a negative start, or an end less than start, throws. The fault is the arguments passed to .slice() on an iterable result (often from datastore scan helpers), not the data itself.

Source

Thrown at packages/gatsby/src/datastore/common/iterable.ts:51

      }
    }
  }

  concat<U>(other: Iterable<U>): GatsbyIterable<T | U> {
    return new GatsbyIterable(() => concatSequence(this, other))
  }

  map<U>(fn: (entry: T, index: number) => U): GatsbyIterable<U> {
    return new GatsbyIterable(() => mapSequence(this, fn))
  }

  filter(predicate: (entry: T) => unknown): GatsbyIterable<T> {
    return new GatsbyIterable(() => filterSequence(this, predicate))
  }

  slice(start: number, end?: number): GatsbyIterable<T> {
    if ((typeof end !== `undefined` && end < start) || start < 0)
      throw new Error(
        `Both arguments must not be negative and end must be greater than start`
      )
    return new GatsbyIterable<T>(() => sliceSequence(this, start, end))
  }

  deduplicate(keyFn?: (entry: T) => unknown): GatsbyIterable<T> {
    return new GatsbyIterable<T>(() => deduplicateSequence(this, keyFn))
  }

  forEach(callback: (entry: T, index: number) => unknown): void {
    let i = 0
    for (const value of this) {
      callback(value, i++)
    }
  }

  /**
   * Assuming both this and the other iterable are sorted

View on GitHub (pinned to e85d62f177)

Solutions

  1. Pass non-negative start and ensure end >= start
  2. Guard slice bounds before calling when they come from user input
  3. Use undefined for end to slice to the finish
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/gatsby/src/datastore/common/iterable.ts:51 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gatsbyjs/gatsby@e85d62f177 (2026-08-26). Data as JSON: /api/errors/11b624dbe0bfc35b. Report an issue: GitHub.