[icinga-checkins] icinga.org: icingaweb2-module-director/bugfix/loop-templateresolver-11803: Sync: Tell the user which object caused an Exception

git at icinga.org git at icinga.org
Mon Oct 31 13:31:44 CET 2016


Module: icingaweb2-module-director
Branch: bugfix/loop-templateresolver-11803
Commit: 5199dc78266c404dad9b3b79893fdb1c794eb2e1
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=5199dc78266c404dad9b3b79893fdb1c794eb2e1

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Thu Oct 27 15:43:26 2016 +0200

Sync: Tell the user which object caused an Exception

---

 library/Director/Import/Sync.php |   25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php
index 28fc482..a8fe247 100644
--- a/library/Director/Import/Sync.php
+++ b/library/Director/Import/Sync.php
@@ -4,7 +4,7 @@ namespace Icinga\Module\Director\Import;
 
 use Exception;
 use Icinga\Data\Filter\Filter;
-use Icinga\Module\Director\Import\SyncUtils;
+use Icinga\Module\Director\Db;
 use Icinga\Module\Director\Objects\IcingaObject;
 use Icinga\Module\Director\Objects\ImportSource;
 use Icinga\Module\Director\Objects\IcingaService;
@@ -21,6 +21,11 @@ class Sync
     protected $rule;
 
     /**
+     * @var Db
+     */
+    protected $db;
+
+    /**
      * Related ImportSource objects
      *
      * @var array
@@ -63,6 +68,9 @@ class Sync
 
     protected $syncProperties;
 
+    /**
+     * @var SyncRun
+     */
     protected $run;
 
     protected $runStartTime;
@@ -72,6 +80,8 @@ class Sync
     /**
      * Constructor. No direct initialization allowed right now. Please use one
      * of the available static factory methods
+     *
+     * @param SyncRule $rule
      */
     public function __construct(SyncRule $rule)
     {
@@ -240,6 +250,7 @@ class Sync
         $combinedKey = $this->rule->hasCombinedKey();
 
         foreach ($this->sources as $source) {
+            /** @var ImportSource $source */
             $sourceId = $source->id;
 
             // Provide an alias column for our key. TODO: double-check this!
@@ -544,6 +555,8 @@ class Sync
         $dba = $db->getDbAdapter();
         $dba->beginTransaction();
 
+        $object = null;
+
         try {
             $formerActivityChecksum = Util::hex2binary(
                 $db->getLastActivityChecksum()
@@ -604,7 +617,15 @@ class Sync
 
         } catch (Exception $e) {
             $dba->rollBack();
-            throw $e;
+            if ($object !== null && $object instanceof IcingaObject) {
+                throw new IcingaException(
+                    'Exception while syncing %s %s: %s',
+                    get_class($object), $object->get('object_name'), $e->getMessage(), $e
+                );
+            }
+            else {
+                throw $e;
+            }
         }
 
         return $this->run->id;



More information about the icinga-checkins mailing list