{"record":{"id":"ca122b93425b000e","repo":"chroma-core/chroma","slug":"expected-include-to-be-a-non-empty-array","errorCode":null,"errorMessage":"Expected 'include' to be a non-empty array","messagePattern":"Expected 'include' to be a non-empty array","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":724,"sourceCode":"  }\n};\n\n/**\n * Validates include fields for query operations.\n * @param options - Validation options\n * @param options.include - Array of fields to include in results\n * @param options.exclude - Optional array of fields that should not be included\n * @throws ChromaValueError if include fields are invalid\n */\nexport const validateInclude = ({\n  include,\n  exclude,\n}: {\n  include: Include[];\n  exclude?: Include[];\n}) => {\n  if (!Array.isArray(include)) {\n    throw new ChromaValueError(\"Expected 'include' to be a non-empty array\");\n  }\n\n  const validValues = Object.keys(IncludeEnum);\n  include.forEach((item) => {\n    if (typeof (item as any) !== \"string\") {\n      throw new ChromaValueError(\"Expected 'include' items to be strings\");\n    }\n\n    if (!validValues.includes(item)) {\n      throw new ChromaValueError(\n        `Expected 'include' items to be one of ${validValues.join(\n          \", \",\n        )}, but got ${item}`,\n      );\n    }\n\n    if (exclude?.includes(item)) {\n      throw new ChromaValueError(`${item} is not allowed for this operation`);","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L706-L742","documentation":"The include option of collection.get() and query() must be an array of IncludeEnum values; validateInclude throws this ChromaValueError when Array.isArray(include) is false (utils.ts:723-725). Only array-ness is checked at this step — a bare string like 'documents', a single unwrapped enum member, or an object all fail here.","triggerScenarios":"collection.get({ include: 'documents' }); include: IncludeEnum.Documents (single value not wrapped in brackets); include: { documents: true } — typical when the value comes from parsed JSON or env config.","commonSituations":"Reading include from user-supplied JSON where a single field was given as a scalar; forgetting the brackets when only one field is requested.","solutions":["Always pass an array: include: ['documents', 'metadatas']","Use IncludeEnum members as elements: include: [IncludeEnum.Documents]","Normalize untyped config at the boundary: include: [].concat(rawInclude)"],"exampleFix":"// before\nawait col.get({ include: 'metadatas' });\n\n// after\nawait col.get({ include: ['metadatas'] });","handlingStrategy":"validation","validationCode":"const includeList = Array.isArray(rawInclude) ? rawInclude : [rawInclude];\nawait col.get({ include: includeList });","typeGuard":"import { IncludeEnum, type Include } from 'chromadb';\nconst isIncludeArray = (v: unknown): v is Include[] =>\n  Array.isArray(v) && v.every(i => typeof i === 'string' && i in IncludeEnum);","tryCatchPattern":null,"preventionTips":["Always pass include as an array literal, even for a single field","Normalize untyped config with [].concat(value) before it reaches the client","Type include parameters as Include[] so scalars fail to compile"],"tags":["javascript","typescript","validation","include","query-options"],"backgroundTag":"invalid-include-parameter","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}