From 4081ae07cf7bd095228212dbb84b94b21c3159e2 Mon Sep 17 00:00:00 2001
From: Hemanth Nakkina <hemanth.nakkina@canonical.com>
Date: Wed, 22 May 2024 08:52:14 +0530
Subject: [PATCH] Log db sync failures during retry

Currently there is no log on why the db sync
failed and charm retries the db sync. Add log
on pebble exec error for db sync and reraise
the error.

Change-Id: I103b1b044a7fb55b1fb05bb1e8a461cad3c20c5c
---
 ops-sunbeam/ops_sunbeam/charm.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/ops-sunbeam/ops_sunbeam/charm.py b/ops-sunbeam/ops_sunbeam/charm.py
index 11f6921d..3f82c9c1 100644
--- a/ops-sunbeam/ops_sunbeam/charm.py
+++ b/ops-sunbeam/ops_sunbeam/charm.py
@@ -675,8 +675,12 @@ class OSBaseOperatorCharmK8S(OSBaseOperatorCharm):
     def _retry_db_sync(self, cmd):
         container = self.unit.get_container(self.db_sync_container_name)
         logging.debug("Running sync: \n%s", cmd)
-        process = container.exec(cmd, timeout=5 * 60)
-        out, err = process.wait_output()
+        try:
+            process = container.exec(cmd, timeout=5 * 60)
+            out, err = process.wait_output()
+        except ops.pebble.ExecError as e:
+            logger.warning(f"DB Sync pebble exec error: {str(e)}")
+            raise e
         if err:
             for line in err.splitlines():
                 logger.warning("DB Sync stderr: %s", line.strip())