{"record":{"id":"b0f44741bf2c9d52","repo":"hcengineering/platform","slug":"all-predicate-requires-array","errorCode":null,"errorMessage":"$all predicate requires array","messagePattern":"\\$all predicate requires array","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/core/packages/core/src/predicate.ts","lineNumber":56,"sourceCode":"\nconst predicates: Record<string, PredicateFactory> = {\n  $in: (o, propertyKey) => {\n    if (!Array.isArray(o)) {\n      throw new Error('$in predicate requires array')\n    }\n    return (docs) =>\n      execPredicate(docs, propertyKey, (value) => {\n        if (Array.isArray(value)) {\n          return o.some((p) => value.includes(p))\n        } else {\n          // eslint-disable-next-line eqeqeq\n          return o.some((p) => p == value)\n        }\n      })\n  },\n  $all: (o, propertyKey) => {\n    if (!Array.isArray(o)) {\n      throw new Error('$all predicate requires array')\n    }\n    return (docs) =>\n      execPredicate(docs, propertyKey, (value: any[]) => {\n        for (const val of o) {\n          if (!value.includes(val)) return false\n        }\n        return true\n      })\n  },\n  $nin: (o, propertyKey) => {\n    if (!Array.isArray(o)) {\n      throw new Error('$nin predicate requires array')\n    }\n    return (docs) =>\n      execPredicate(docs, propertyKey, (value) => {\n        if (Array.isArray(value)) {\n          return !o.some((p) => value.includes(p))\n        } else {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/core/packages/core/src/predicate.ts#L38-L74","documentation":"The $all predicate matches documents whose array property contains every element of the given list, so its argument must be an array. predicate.ts validates this immediately when the predicate is created and throws this error otherwise. It is an argument-validation failure, not a data failure.","triggerScenarios":"Queries like { tags: { $all: 'red' } } (scalar instead of array) or { tags: { $all: requiredTags } } where requiredTags is undefined, null, or an object such as a Set spread incorrectly.","commonSituations":"Forgetting to wrap a single required value in an array; a tags/roles list coming from configuration or a remote call as undefined; converting a Set to a query without Array.from.","solutions":["Pass an explicit array: { $all: ['red', 'blue'] }.","Coerce Sets/iterables with Array.from before querying.","Default missing lists to an empty array or skip the predicate when the list is absent."],"exampleFix":"// before\nconst q = { tags: { $all: new Set(['a', 'b']) } }\n// after\nconst q = { tags: { $all: Array.from(new Set(['a', 'b'])) } }","handlingStrategy":"validation","validationCode":"const all: unknown = requiredTags\nif (!Array.isArray(all)) throw new TypeError('$all expects an array, got: ' + typeof all)\nconst q = { tags: { $all: all } }","typeGuard":"function isReadonlyArray(v: unknown): v is readonly unknown[] {\n  return Array.isArray(v)\n}","tryCatchPattern":"try {\n  return await find(clazz, { tags: { $all: tags } })\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('$all predicate requires array')) {\n    return [] // or retry with normalized [tags]\n  }\n  throw e\n}","preventionTips":["Convert Sets/iterables with Array.from before querying.","Default absent lists to [] or omit the predicate entirely.","Add unit tests for query builders feeding dynamic tag/role lists."],"tags":["query","predicate","type-error"],"backgroundTag":"predicate-requires-array","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}