nocobase/nocobase · error · Error

Invalid conditions: conditions must be an object

Error message

Invalid conditions: conditions must be an object

What it means

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).

Source

Thrown at packages/core/utils/src/transformFilter.ts:313

 *       path: 'name',
 *       operator: '$eq',
 *       value: 'test'
 *     },
 *     {
 *       path: 'age',
 *       operator: '$gt',
 *       value: 18
 *     }
 *   ]
 * };
 *
 * const result = evaluateConditions(conditions, evaluator);
 * // 返回: boolean (根据评估器的具体实现)
 * ```
 */
export function evaluateConditions(conditions: FilterGroupType, evaluator: ConditionEvaluator): boolean {
  if (!conditions || typeof conditions !== 'object') {
    throw new Error('Invalid conditions: conditions must be an object');
  }

  if (!isFilterGroup(conditions)) {
    throw new Error('Invalid conditions: conditions must have logic and items properties');
  }

  if (!Array.isArray(conditions.items)) {
    throw new Error('Invalid conditions: items must be an array');
  }

  if (typeof evaluator !== 'function') {
    throw new Error('Invalid evaluator: evaluator must be a function');
  }

  return evaluateGroup(conditions, evaluator);
}

View on GitHub (pinned to fa42722fef)

Solutions

  1. Inspect where conditions come from and ensure the rule is only evaluated when a conditions object exists.
  2. Default to an inert group, e.g. conditions ?? { logic: '$and', items: [] }, which evaluates to true.
  3. If the value is a JSON string, JSON.parse it (with error handling) before calling.
  4. Re-save or repair the rule configuration that is missing its conditions.

Example fix

// before
const ok = evaluateConditions(rule.conditions, evaluator); // rule.conditions is null
// after
const ok = rule.conditions ? evaluateConditions(rule.conditions, evaluator) : true;
Defensive patterns

Strategy: validation

Validate before calling

if (conditions && typeof conditions === 'object') {
  const ok = evaluateConditions(conditions, evaluator);
} else {
  const ok = true; // no conditions configured -> rule matches
}

Type guard

function isConditionGroup(x: unknown): x is FilterGroupType {
  return typeof x === 'object' && x !== null && 'logic' in x && 'items' in x;
}

Try / catch

let ok: boolean;
try {
  ok = evaluateConditions(conditions, evaluator);
} catch (err) {
  if (err instanceof Error && err.message.startsWith('Invalid conditions')) {
    ok = true; // treat malformed/unset conditions as matched, or log and skip
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of nocobase/nocobase@fa42722fef (2026-09-01). Data as JSON: /api/errors/9d7bc4b5250f709f. Report an issue: GitHub.