chroma-core/chroma · error · TypeError

Invalid limit input

Error message

Invalid limit input

What it means

Limit.from() accepts a Limit instance, a plain number, an object (LimitOptions), or null/undefined. Any other input type — a string like "10", a boolean, an array — matches no branch and raises this TypeError before a Limit is constructed.

Source

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

  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();
    }

    if (typeof input === "object") {
      return new Limit(input as LimitOptions);
    }

    throw new TypeError("Invalid limit input");
  }

  public toJSON(): { offset: number; limit?: number } {
    const result: { offset: number; limit?: number } = { offset: this.offset };
    if (this.limit !== undefined) {
      result.limit = this.limit;
    }
    return result;
  }
}

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Convert strings to numbers first: Limit.from(Number(req.query.limit))
  2. Pass a plain number or an options object: Limit.from(20) or Limit.from({ limit: 20, offset: 40 })
  3. Normalize at the API boundary: coerce and validate query params once, then work with numbers internally

Example fix

// before
Limit.from(req.query.limit); // "20" (string) -> TypeError

// after
Limit.from(req.query.limit ? Number(req.query.limit) : undefined);
Defensive patterns

Strategy: type-guard

Validate before calling

const raw = req.query.limit;
const value = raw === undefined || raw === null || raw === "" ? undefined : Number(raw);
if (value !== undefined && (Number.isNaN(value) || !Number.isInteger(value))) {
  throw new Error(`limit must be an integer, got ${raw}`);
}
const limit = Limit.from(value);

Type guard

function isLimitInput(v: unknown): v is number | LimitOptions | Limit | null | undefined {
  return (
    v == null ||
    typeof v === "number" ||
    v instanceof Limit ||
    (typeof v === "object" && !Array.isArray(v))
  );
}

Prevention

When it happens

Trigger: Limit.from("10"); Limit.from(true); or Limit.from(req.query.limit) where query parameters are always strings. Also Limit.from([20]) from code assuming array input is accepted.

Common situations: HTTP query parameters (always strings in Node/Express) piped straight into Limit.from. Values from JSON files that were saved as strings. Feature flags booleans accidentally forwarded as the limit.

Related errors


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