phacility/phabricator · error · HeraldInvalidConditionException

Unknown condition "%s"!

Error message

Unknown condition "%s"!

What it means

Thrown by HeraldAdapter::willSaveCondition() when the condition's field/type value (getFieldCondition()) matches none of the CONDITION_* cases in the switch — the switch falls through to 'default'. It means the condition type string being saved is not one this version of HeraldAdapter knows about. The comment in the source notes several types get no validation, but any unrecognized type is rejected outright.

Source

Thrown at src/applications/herald/adapter/HeraldAdapter.php:696

      case self::CONDITION_INCLUDE_ANY:
      case self::CONDITION_INCLUDE_NONE:
      case self::CONDITION_IS_ME:
      case self::CONDITION_IS_NOT_ME:
      case self::CONDITION_RULE:
      case self::CONDITION_NOT_RULE:
      case self::CONDITION_EXISTS:
      case self::CONDITION_NOT_EXISTS:
      case self::CONDITION_UNCONDITIONALLY:
      case self::CONDITION_NEVER:
      case self::CONDITION_HAS_BIT:
      case self::CONDITION_NOT_BIT:
      case self::CONDITION_IS_TRUE:
      case self::CONDITION_IS_FALSE:
        // No explicit validation for these types, although there probably
        // should be in some cases.
        break;
      default:
        throw new HeraldInvalidConditionException(
          pht(
            'Unknown condition "%s"!',
            $condition_type));
    }
  }


/* -(  Actions  )------------------------------------------------------------ */

  private function getActionImplementationMap() {
    if ($this->actionMap === null) {
      // We can't use PhutilClassMapQuery here because action expansion
      // depends on the adapter and object.

      $object = $this->getObject();

      $map = array();
      $all = HeraldAction::getAllActions();

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Inspect the saved condition type string (the '%s' in the message) and compare it against the CONDITION_ constants / condition keys the target adapter actually supports (see the adapter's getConditionImplementationMap / getXAction... list).
  2. If the rule came from a newer Phabricator, upgrade the install (or edit the rule on the newer install) — matching the config-version guidance in HeraldRuleController.
  3. Delete and recreate the offending condition in the UI so a known-good type is submitted.
  4. If you maintain a custom adapter, add the new condition type to the willSaveCondition() switch (or map it correctly) before shipping rules that use it.

Example fix

// before (script writes a raw, unknown condition type)
$cond->setFieldName('title');
$cond->setFieldCondition('regex'); // typo / unknown key

// after
$cond->setFieldCondition(HeraldAdapter::CONDITION_REGEXP); // 'regexp'
Defensive patterns

Strategy: validation

Validate before calling

// Before saving, confirm the condition type is one this adapter supports
$valid = array_keys($adapter->getConditionTypeMap()); // adapter-known keys
if (!in_array($condition->getFieldCondition(), $valid, true)) {
  return pht('Unsupported condition type for this adapter.');
}

Type guard

function isKnownHeraldConditionType(HeraldAdapter $adapter, $type) {
  return in_array($type, array_keys($adapter->getConditionTypeMap()), true);
}

Try / catch

try {
  $editor->save();
} catch (HeraldInvalidConditionException $ex) {
  if (strpos($ex->getMessage(), 'Unknown condition') === 0) {
    // drop/recreate the condition with a supported constant; likely
    // version skew if the rule was authored on a newer install
  }
  throw $ex;
}

Prevention

When it happens

Trigger: A rule-save payload (the 'rule' JSON from the edit UI, or a programmatic HeraldEditor call) contains a condition whose type string is misspelled, from another adapter, or from a newer/older Phabricator version (e.g. 'regexp' vs 'regexp-pair', or a custom condition key not registered in the adapter's condition implementation map).

Common situations: Version skew: a rule exported/created on a newer Phabricator that added a new condition type is edited on an older install. Hand-crafted API requests or scripts writing HeraldRule conditions with the wrong constant. Custom adapter development where a new condition key was not wired into willSaveCondition's switch.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/e9e56e15d9048778. Report an issue: GitHub.