{"record":{"id":"9d7bc4b5250f709f","repo":"nocobase/nocobase","slug":"invalid-conditions-conditions-must-be-an-object","errorCode":null,"errorMessage":"Invalid conditions: conditions must be an object","messagePattern":"Invalid conditions: conditions must be an object","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/utils/src/transformFilter.ts","lineNumber":313,"sourceCode":" *       path: 'name',\n *       operator: '$eq',\n *       value: 'test'\n *     },\n *     {\n *       path: 'age',\n *       operator: '$gt',\n *       value: 18\n *     }\n *   ]\n * };\n *\n * const result = evaluateConditions(conditions, evaluator);\n * // 返回: boolean (根据评估器的具体实现)\n * ```\n */\nexport function evaluateConditions(conditions: FilterGroupType, evaluator: ConditionEvaluator): boolean {\n  if (!conditions || typeof conditions !== 'object') {\n    throw new Error('Invalid conditions: conditions must be an object');\n  }\n\n  if (!isFilterGroup(conditions)) {\n    throw new Error('Invalid conditions: conditions must have logic and items properties');\n  }\n\n  if (!Array.isArray(conditions.items)) {\n    throw new Error('Invalid conditions: items must be an array');\n  }\n\n  if (typeof evaluator !== 'function') {\n    throw new Error('Invalid evaluator: evaluator must be a function');\n  }\n\n  return evaluateGroup(conditions, evaluator);\n}\n","sourceCodeStart":295,"sourceCodeEnd":330,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/core/utils/src/transformFilter.ts#L295-L330","documentation":"evaluateConditions() evaluates a structured filter group against a condition evaluator and returns a boolean. It first requires the conditions argument to be a non-null object; primitives, null, or undefined cannot form a condition group, so it throws immediately. This is the entry-point guard for the whole evaluation pipeline (validate shape → validate evaluator → evaluateGroup).","triggerScenarios":"Calling evaluateConditions(null, evaluator), evaluateConditions(undefined, evaluator), evaluateConditions('$and', evaluator), or passing a non-object value from callers like matched() / linkageAssignField() when the configured condition failed to load or resolve.","commonSituations":"A linkage/visibility rule whose conditions option was never configured (undefined); an expression or variable resolving to a string; stale stored config where conditions were removed but the rule remained.","solutions":["Inspect where conditions come from and ensure the rule is only evaluated when a conditions object exists.","Default to an inert group, e.g. conditions ?? { logic: '$and', items: [] }, which evaluates to true.","If the value is a JSON string, JSON.parse it (with error handling) before calling.","Re-save or repair the rule configuration that is missing its conditions."],"exampleFix":"// before\nconst ok = evaluateConditions(rule.conditions, evaluator); // rule.conditions is null\n// after\nconst ok = rule.conditions ? evaluateConditions(rule.conditions, evaluator) : true;","handlingStrategy":"validation","validationCode":"if (conditions && typeof conditions === 'object') {\n  const ok = evaluateConditions(conditions, evaluator);\n} else {\n  const ok = true; // no conditions configured -> rule matches\n}","typeGuard":"function isConditionGroup(x: unknown): x is FilterGroupType {\n  return typeof x === 'object' && x !== null && 'logic' in x && 'items' in x;\n}","tryCatchPattern":"let ok: boolean;\ntry {\n  ok = evaluateConditions(conditions, evaluator);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Invalid conditions')) {\n    ok = true; // treat malformed/unset conditions as matched, or log and skip\n  } else throw err;\n}","preventionTips":["Check that the rule's conditions option exists before evaluating; treat undefined as 'no rule'.","Parse JSON-string conditions with error handling before use.","Validate conditions at save time so unset/corrupt rules are rejected early.","Never pass raw variables that may resolve to strings; resolve to objects first."],"tags":["validation","filter","type-error"],"backgroundTag":"invalid-filter-group","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}