chroma-core/chroma · error · TypeError

Limit must be a positive integer when provided

Error message

Limit must be a positive integer when provided

What it means

When a limit value is provided (not null/undefined), the Limit constructor requires it to be a positive integer. limit: 0 is explicitly rejected — unlike offset, there is no 'zero means all' semantics; omit the limit entirely to leave it unbounded.

Source

Thrown at clients/new-js/packages/chromadb/src/execution/expression/limit.ts:21

  limit?: number | null | undefined;
}

export type LimitInput = Limit | number | LimitOptions | null | undefined;

export class Limit {
  public readonly offset: number;
  public readonly limit?: number;

  constructor(options: LimitOptions = {}) {
    const { offset = 0, limit } = options;

    if (!Number.isInteger(offset) || offset < 0) {
      throw new TypeError("Limit offset must be a non-negative integer");
    }

    if (limit !== null && limit !== undefined) {
      if (!Number.isInteger(limit) || limit <= 0) {
        throw new TypeError("Limit must be a positive integer when provided");
      }
      this.limit = limit;
    }

    this.offset = offset;
  }

  public static from(input: LimitInput, offsetOverride?: number): Limit {
    if (input instanceof Limit) {
      return new Limit({ offset: input.offset, limit: input.limit });
    }

    if (typeof input === "number") {
      return new Limit({ limit: input, offset: offsetOverride ?? 0 });
    }

    if (input === null || input === undefined) {
      return new Limit();

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. To express 'no limit', omit the limit: new Limit({ offset }) or new Limit({ limit: undefined })
  2. Clamp provided values: Math.max(1, Math.floor(Number(size)))
  3. Validate external page-size input and reject/clamp 0 before constructing Limit

Example fix

// before
new Limit({ limit: size || 0 }); // size = 0 -> limit 0 -> TypeError

// after
new Limit({ limit: size > 0 ? Math.floor(size) : undefined }); // undefined = unbounded
Defensive patterns

Strategy: validation

Validate before calling

const size = Number(req.query.size);
const limit = new Limit({
  offset,
  limit: Number.isInteger(size) && size > 0 ? size : undefined, // undefined = unbounded
});

Type guard

const isValidLimit = (v: unknown): v is number =>
  typeof v === "number" && Number.isInteger(v) && v > 0;

Prevention

When it happens

Trigger: new Limit({ limit: 0 }); new Limit({ limit: -5 }); new Limit({ limit: 10.5 }); or Limit.from(0). Fractional limits come from dividing counts (limit: total / 3).

Common situations: Application semantics where 0 means 'no cap' — in this API you must pass null/undefined instead. Size parameters read from config or query strings defaulting to 0. Percentage-based limits computed as fractions.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/db257a2310c01558. Report an issue: GitHub.