From 7c4647ce4b2c589bf85471d3eb19e7685fc092a2 Mon Sep 17 00:00:00 2001 From: MJ Ponsonby Date: Wed, 25 Feb 2026 09:32:54 +0000 Subject: [PATCH] Make wrap_snap_operations return the actual error. Currently wrap_snap_operations just returns minimal error messages including only the names of the snaps that failed and not why. This is not particularly useful so I've expanded this to return include the actual error as well. Signed-off-by: MJ Ponsonby --- lib/charms/operator_libs_linux/v2/snap.py | 4 ++-- tests/unit/test_snap.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/charms/operator_libs_linux/v2/snap.py b/lib/charms/operator_libs_linux/v2/snap.py index 71e44ce0..97c66d97 100644 --- a/lib/charms/operator_libs_linux/v2/snap.py +++ b/lib/charms/operator_libs_linux/v2/snap.py @@ -1288,10 +1288,10 @@ def _wrap_snap_operations( snaps.append(snap) except SnapError as e: # noqa: PERF203 logger.warning("Failed to %s snap %s: %s!", op, s, e.message) - errors.append(s) + errors.append(e.message) except SnapNotFoundError: logger.warning("Snap '%s' not found in cache!", s) - errors.append(s) + errors.append(f"Snap '{s}' not found in cache!") if errors: raise SnapError(f"Failed to install or refresh snap(s): {', '.join(errors)}") diff --git a/tests/unit/test_snap.py b/tests/unit/test_snap.py index a98c93f4..b97a09a8 100644 --- a/tests/unit/test_snap.py +++ b/tests/unit/test_snap.py @@ -1095,7 +1095,10 @@ def __getitem__(self, name: str) -> snap.Snap: snap.add("nothere") repr(ctx.exception) # ensure custom __repr__ doesn't error self.assertEqual("", ctx.exception.name) - self.assertIn("Failed to install or refresh snap(s): nothere", ctx.exception.message) + self.assertIn( + "Failed to install or refresh snap(s): Snap 'nothere' not found in cache!", + ctx.exception.message, + ) def test_snap_get(self): """Test the multiple different ways of calling the Snap.get function.