phacility/phabricator · error · Exception

Object is of wrong type for adapter!

Error message

Object is of wrong type for adapter!

What it means

Thrown by HeraldRuleController for object-bound rules after the target object loaded successfully: the selected adapter's canTriggerOnObject($object) returned false. Each Herald adapter declares which object types it can attach to (via isTestAdapterForObject/canTriggerOnObject in HeraldAdapter.php:275), so this error means the rule's content type (adapter) does not accept the provided object's concrete class.

Source

Thrown at src/applications/herald/controller/HeraldRuleController.php:91

      if ($rule->isObjectRule()) {
        $rule->setTriggerObjectPHID($request->getStr('targetPHID'));
        $object = id(new PhabricatorObjectQuery())
          ->setViewer($viewer)
          ->withPHIDs(array($rule->getTriggerObjectPHID()))
          ->requireCapabilities(
            array(
              PhabricatorPolicyCapability::CAN_VIEW,
              PhabricatorPolicyCapability::CAN_EDIT,
            ))
          ->executeOne();
        if (!$object) {
          throw new Exception(
            pht('No valid object provided for object rule!'));
        }

        if (!$adapter->canTriggerOnObject($object)) {
          throw new Exception(
            pht('Object is of wrong type for adapter!'));
        }
      }

      $cancel_uri = $this->getApplicationURI();
    }

    if ($rule->isGlobalRule()) {
      $this->requireApplicationCapability(
        HeraldManageGlobalRulesCapability::CAPABILITY);
    }

    $adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType());

    $local_version = id(new HeraldRule())->getConfigVersion();
    if ($rule->getConfigVersion() > $local_version) {
      throw new Exception(
        pht(

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Match the adapter/content type to the object: pick the 'X rules' adapter that corresponds to the object you are targeting (task adapter for tasks, revision adapter for revisions).
  2. Re-select the target object AFTER choosing the rule type in the editor so the form submits a consistent pair.
  3. If you develop a custom adapter, extend canTriggerOnObject()/isTestAdapterForObject() to return true for your object class.

Example fix

// before — mismatched pair submitted
content type: differential.revision
targetPHID:  PHID-TASK-xxxx (a Maniphest task)

// after
content type: maniphest.task
targetPHID:  PHID-TASK-xxxx
Defensive patterns

Strategy: validation

Validate before calling

// Verify adapter/object compatibility before submitting the save
$adapter = HeraldAdapter::getAdapterForContentType($content_type);
if (!$adapter->canTriggerOnObject($object)) {
  return pht('This rule type cannot trigger on that object.');
}

Type guard

function adapterAcceptsObject($content_type, $object) {
  $adapter = HeraldAdapter::getAdapterForContentType($content_type);
  return $adapter && $adapter->canTriggerOnObject($object);
}

Try / catch

try {
  // object-rule save path
} catch (Exception $ex) {
  if (strpos($ex->getMessage(), 'wrong type for adapter') !== false) {
    // prompt user to re-pick adapter or object so the pair is consistent
  }
}

Prevention

When it happens

Trigger: Creating an object rule where the chosen adapter/content type disagrees with the target: e.g. an adapter selected for Differential revisions combined with a Maniphest task PHID as targetPHID, or any custom object type the adapter's canTriggerOnObject() does not whitelist.

Common situations: UI state gets out of sync when the user changes the adapter dropdown after choosing an object, or scripts POST a content-type/target combination that the UI would never produce. Custom applications adding new object types without updating the adapter's canTriggerOnObject() implementation.

Related errors


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