{"record":{"id":"69bf3cab948050f8","repo":"chroma-core/chroma","slug":"invalid-where-clause-at-index-index","errorCode":null,"errorMessage":"Invalid where clause at index ${index}","messagePattern":"Invalid where clause at index (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/execution/expression/where.ts","lineNumber":170,"sourceCode":"    (key, value) => new ComparisonWhere(key, \"$not_contains\", value),\n  ],\n  [\"$regex\", (key, value) => new ComparisonWhere(key, \"$regex\", value)],\n  [\"$not_regex\", (key, value) => new ComparisonWhere(key, \"$not_regex\", value)],\n]);\n\nconst parseWhereDict = (data: Record<string, unknown>): WhereExpression => {\n  if (\"$and\" in data) {\n    if (Object.keys(data).length !== 1) {\n      throw new Error(\"$and cannot be combined with other keys\");\n    }\n    const rawConditions = data[\"$and\"];\n    if (!Array.isArray(rawConditions) || rawConditions.length === 0) {\n      throw new TypeError(\"$and must be a non-empty array\");\n    }\n    const conditions = rawConditions.map((item, index) => {\n      const expr = WhereExpression.from(item as WhereInput);\n      if (!expr) {\n        throw new TypeError(`Invalid where clause at index ${index}`);\n      }\n      return expr;\n    });\n    if (conditions.length === 1) {\n      return conditions[0];\n    }\n    return conditions\n      .slice(1)\n      .reduce(\n        (acc, condition) => AndWhere.combine(acc, condition),\n        conditions[0],\n      );\n  }\n\n  if (\"$or\" in data) {\n    if (Object.keys(data).length !== 1) {\n      throw new Error(\"$or cannot be combined with other keys\");\n    }","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/execution/expression/where.ts#L152-L188","documentation":"Thrown while parsing an $and (or $or) array (where.ts:170) when the clause at the reported index converts to undefined — which, given WhereExpression.from's rules, means the entry is null or undefined. Entries of other wrong types (strings, numbers, arrays) throw the separate 'Where input must be a WhereExpression or plain object' error instead, so this message pinpoints null/undefined holes in your clause list. The index in the message is the exact position in the $and/$or array.","triggerScenarios":"Passing { $and: [{ a: 1 }, null] } — index 1 is null; { $or: [maybeFilterA, maybeFilterB] } where optional filters resolved to undefined; clauses built with map/ternaries that yield undefined for disabled features: conds.map(c => c ? build(c) : undefined).","commonSituations":"Optional-filter pipelines that map features to clauses and forget to filter out the undefined entries; sparse arrays or deleted indices; API payloads where a filter slot is null meaning 'not applicable'.","solutions":["Remove null/undefined entries before use: clauses.filter(c => c != null)","Give disabled filters a neutral clause or build the array only from enabled features (for...of push)","Read the reported index to locate the exact offending entry in your $and/$or array"],"exampleFix":"// before\nconst where = { $and: features.map(f => filters[f]) }; // undefined holes\n\n// after\nconst where = { $and: features.map(f => filters[f]).filter(c => c != null) };","handlingStrategy":"validation","validationCode":"const clauses = rawClauses\n  .map(c => (c == null ? undefined : c))\n  .filter((c): c is Record<string, unknown> => c != null);\nif (clauses.length === 0) throw new Error('empty where clause list');\nconst where = { $and: clauses };","typeGuard":"const isWhereClause = (v: unknown): v is Record<string, unknown> =>\n  typeof v === 'object' && v !== null && !Array.isArray(v);","tryCatchPattern":"try {\n  const results = await collection.query({ where });\n} catch (e) {\n  if (e instanceof TypeError && /Invalid where clause at index (\\d+)/.test(e.message)) {\n    const idx = Number(/(\\d+)/.exec(e.message)?.[1]);\n    return collection.query({ where: { $and: clauses.filter((_, i) => i !== idx) } });\n  }\n  throw e;\n}","preventionTips":["Filter null/undefined out of clause arrays before use — the error's index names the exact hole","Map-then-filter when building optional clauses: .map(build).filter(c => c != null)","A null slot does not mean 'match all'; it is always an error"],"tags":["where","and","null-clause","query-filter","input-validation"],"backgroundTag":"invalid-query-filter","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}