Throw exception when baoName is not found
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 23 Jun 2021 05:31:40 +0000 (17:31 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 25 Jun 2021 02:39:38 +0000 (14:39 +1200)
It the BAO name is not found at this point we currently get a fatal error. This makes it more
recoverable. The specific case I'm hitting at the moment relates to monolog - the
caching of the symfony container means it persists between builds and is
accessed before the extension is installed. However the entity is not
yet registered. Historically I have hit this fatal in other
scenarios but I can't recall the details.

Civi/Api4/Generic/DAOGetAction.php

index 07cefdf0c8f2839264141447f08109920df2c6c7..f374047486b853dea3bf37222471b2999a097f0a 100644 (file)
@@ -78,9 +78,17 @@ class DAOGetAction extends AbstractGetAction {
    */
   protected $having = [];
 
+  /**
+   * @throws \API_Exception
+   * @throws \CRM_Core_Exception
+   */
   public function _run(Result $result) {
     // Early return if table doesn't exist yet due to pending upgrade
     $baoName = $this->getBaoName();
+    if (!$baoName) {
+      // In some cases (eg. site spin-up) the code may attempt to call the api before the entity name is registered.
+      throw new \API_Exception("BAO for {$this->getEntityName()} is not available. This could be a load-order issue");
+    }
     if (!$baoName::tableHasBeenAdded()) {
       \Civi::log()->warning("Could not read from {$this->getEntityName()} before table has been added. Upgrade required.", ['civi.tag' => 'upgrade_needed']);
       return;