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.