{"record":{"id":"fbbfe8eb7db41243","repo":"chroma-core/chroma","slug":"expected-ids-to-be-an-array-but-got-typeof-id","errorCode":null,"errorMessage":"Expected 'ids' to be an array, but got ${typeof ids}","messagePattern":"Expected 'ids' to be an array, but got (.+?)","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":190,"sourceCode":"  }\n\n  documents.forEach((document) => {\n    if (!nullable && typeof document !== \"string\" && !document) {\n      throw new ChromaValueError(\n        `Expected each document to be a string, but got ${typeof document}`,\n      );\n    }\n  });\n};\n\n/**\n * Validates an array of IDs for type correctness and uniqueness.\n * @param ids - Array of ID strings to validate\n * @throws ChromaValueError if IDs are not strings, empty, or contain duplicates\n */\nexport const validateIDs = (ids: string[]) => {\n  if (!Array.isArray(ids)) {\n    throw new ChromaValueError(\n      `Expected 'ids' to be an array, but got ${typeof ids}`,\n    );\n  }\n\n  if (ids.length === 0) {\n    throw new ChromaValueError(\"Expected 'ids' to be a non-empty list\");\n  }\n\n  const nonStrings = ids\n    .map((id, i) => [id, i] as [any, number])\n    .filter(([id, _]) => typeof id !== \"string\")\n    .map(([_, i]) => i);\n\n  if (nonStrings.length > 0) {\n    throw new ChromaValueError(\n      `Found non-string IDs at ${nonStrings.join(\", \")}`,\n    );\n  }","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L172-L208","documentation":"ChromaValueError thrown by validateIDs (utils.ts:190) when the ids value is not an Array. validateIDs runs in Collection.prepareRecords (add/update) and also on get/delete/modify paths whenever ids is provided, so this fires client-side across most collection operations.","triggerScenarios":"collection.add({ ids: 'abc', documents: ['x'] }) — a single string id; collection.get({ ids: idSet }) where idSet is a Set; ids as a number or object from user input.","commonSituations":"Passing a Set or generator where an array is required; single-id convenience assumptions; ids arriving as one comma-joined string from a URL param.","solutions":["Wrap or convert: Array.isArray(x) ? x : [x]; for Sets use [...set]","Type ids as string[] at the API boundary","Parse joined strings with .split(',') before calling"],"exampleFix":"// before\nawait collection.get({ ids: req.query.ids }); // 'a,b' string\n// after\nawait collection.get({ ids: String(req.query.ids).split(\",\") });","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(ids)) throw new TypeError(`ids must be an array, got ${typeof ids}`);","typeGuard":"const isIdArray = (v) => Array.isArray(v);","tryCatchPattern":"try { await collection.get({ ids }); } catch (e) { if (e instanceof ChromaValueError && /'ids' to be an array/.test(e.message)) ids = Array.from(ids); else throw e; }","preventionTips":["Convert Sets with [...set] before passing","Wrap single ids in []","Type request params as string[] and parse joined strings with split(',')"],"tags":["chromadb","validation","ids","type-mismatch"],"backgroundTag":"invalid-ids-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}