{"record":{"id":"2f9e074bba68c956","repo":"chroma-core/chroma","slug":"invalid-limit-input","errorCode":null,"errorMessage":"Invalid limit input","messagePattern":"Invalid limit input","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/execution/expression/limit.ts","lineNumber":46,"sourceCode":"\n  public static from(input: LimitInput, offsetOverride?: number): Limit {\n    if (input instanceof Limit) {\n      return new Limit({ offset: input.offset, limit: input.limit });\n    }\n\n    if (typeof input === \"number\") {\n      return new Limit({ limit: input, offset: offsetOverride ?? 0 });\n    }\n\n    if (input === null || input === undefined) {\n      return new Limit();\n    }\n\n    if (typeof input === \"object\") {\n      return new Limit(input as LimitOptions);\n    }\n\n    throw new TypeError(\"Invalid limit input\");\n  }\n\n  public toJSON(): { offset: number; limit?: number } {\n    const result: { offset: number; limit?: number } = { offset: this.offset };\n    if (this.limit !== undefined) {\n      result.limit = this.limit;\n    }\n    return result;\n  }\n}\n","sourceCodeStart":28,"sourceCodeEnd":57,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/execution/expression/limit.ts#L28-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Convert strings to numbers first: Limit.from(Number(req.query.limit))","Pass a plain number or an options object: Limit.from(20) or Limit.from({ limit: 20, offset: 40 })","Normalize at the API boundary: coerce and validate query params once, then work with numbers internally"],"exampleFix":"// before\nLimit.from(req.query.limit); // \"20\" (string) -> TypeError\n\n// after\nLimit.from(req.query.limit ? Number(req.query.limit) : undefined);","handlingStrategy":"type-guard","validationCode":"const raw = req.query.limit;\nconst value = raw === undefined || raw === null || raw === \"\" ? undefined : Number(raw);\nif (value !== undefined && (Number.isNaN(value) || !Number.isInteger(value))) {\n  throw new Error(`limit must be an integer, got ${raw}`);\n}\nconst limit = Limit.from(value);","typeGuard":"function isLimitInput(v: unknown): v is number | LimitOptions | Limit | null | undefined {\n  return (\n    v == null ||\n    typeof v === \"number\" ||\n    v instanceof Limit ||\n    (typeof v === \"object\" && !Array.isArray(v))\n  );\n}","tryCatchPattern":null,"preventionTips":["Convert query-string limits with Number() at the boundary — strings are always rejected","Pass numbers or options objects, never strings or booleans","Centralize pagination param parsing in one helper"],"tags":["chroma","limit","typeerror"],"backgroundTag":"wrong-argument-type","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}