{"record":{"id":"e5cbcafc7e342664","repo":"phacility/phabricator","slug":"condition-references-a-rule-which-does-not-exist","errorCode":null,"errorMessage":"Condition references a rule which does not exist!","messagePattern":"Condition references a rule which does not exist!","errorType":"validation","errorClass":"HeraldInvalidConditionException","httpStatus":null,"severity":"error","filePath":"src/applications/herald/adapter/HeraldAdapter.php","lineNumber":593,"sourceCode":"              pht('First regular expression is invalid!'));\n          }\n          if ($key_matches) {\n            $value_matches = @preg_match($value_regexp, $value);\n            if ($value_matches === false) {\n              throw new HeraldInvalidConditionException(\n                pht('Second regular expression is invalid!'));\n            }\n            if ($value_matches) {\n              return true;\n            }\n          }\n        }\n        return false;\n      case self::CONDITION_RULE:\n      case self::CONDITION_NOT_RULE:\n        $rule = $engine->getRule($condition_value);\n        if (!$rule) {\n          throw new HeraldInvalidConditionException(\n            pht('Condition references a rule which does not exist!'));\n        }\n\n        $is_not = ($condition_type == self::CONDITION_NOT_RULE);\n        $result = $engine->doesRuleMatch($rule, $this);\n        if ($is_not) {\n          $result = !$result;\n        }\n        return $result;\n      case self::CONDITION_HAS_BIT:\n        return (($condition_value & $field_value) === (int)$condition_value);\n      case self::CONDITION_NOT_BIT:\n        return (($condition_value & $field_value) !== (int)$condition_value);\n      default:\n        throw new HeraldInvalidConditionException(\n          pht(\"Unknown condition '%s'.\", $condition_type));\n    }\n  }","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/herald/adapter/HeraldAdapter.php#L575-L611","documentation":"For CONDITION_RULE / CONDITION_NOT_RULE ('linked/other rule' conditions), the condition value is the PHID of another Herald rule; the adapter looks it up with $engine->getRule($condition_value). A null result — the referenced rule does not exist or was not loaded into the engine — throws HeraldInvalidConditionException. Most commonly the referenced rule was deleted while this rule still points at it.","triggerScenarios":"Rule A has a 'rule' condition referencing rule B (by PHID); rule B is deleted or disabled beyond engine visibility; next evaluation of rule A fails with this exception and A stops applying.","commonSituations":"Deleting rules that are still referenced by other rules; moving a rule's content into a new rule and deleting the old one; migrations where referenced PHIDs do not exist in the target instance.","solutions":["Edit the rule and remove or re-point the 'references rule' condition to an existing rule.","If you must delete a rule, first check whether other rules' conditions reference its PHID.","For bulk hygiene, query herald_condition for values equal to deleted rule PHIDs and clean them up."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before saving a rule that references another rule:\n$ref = id(new HeraldRuleQuery())\n  ->setViewer(PhabricatorUser::getOmnipotentUser())\n  ->withPHIDs(array($referenced_rule_phid))\n  ->executeOne();\nif (!$ref) {\n  // do not save the condition - the referenced rule does not exist\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Before deleting a Herald rule, search other rules for conditions referencing its PHID.","After imports/migrations, verify rule-reference conditions still resolve."],"tags":["herald","rule","phabricator"],"backgroundTag":"dangling-foreign-key-reference","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}