From 65d25585f104b810008f899b28def078a397e670 Mon Sep 17 00:00:00 2001 From: David Wilding Date: Thu, 21 Aug 2025 19:57:05 +0800 Subject: [PATCH 1/2] bump patch version --- lib/charms/operator_libs_linux/v0/apt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/charms/operator_libs_linux/v0/apt.py b/lib/charms/operator_libs_linux/v0/apt.py index e2c91398..68846b66 100644 --- a/lib/charms/operator_libs_linux/v0/apt.py +++ b/lib/charms/operator_libs_linux/v0/apt.py @@ -131,7 +131,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 18 +LIBPATCH = 19 PYDEPS = ["opentelemetry-api"] From 7cffdfae85c8979d72f153f761004d1e0b01d173 Mon Sep 17 00:00:00 2001 From: David Wilding Date: Thu, 21 Aug 2025 20:03:11 +0800 Subject: [PATCH 2/2] clarify when `PackageNotFoundError` is raised --- lib/charms/operator_libs_linux/v0/apt.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/charms/operator_libs_linux/v0/apt.py b/lib/charms/operator_libs_linux/v0/apt.py index 68846b66..edd18dcd 100644 --- a/lib/charms/operator_libs_linux/v0/apt.py +++ b/lib/charms/operator_libs_linux/v0/apt.py @@ -35,12 +35,14 @@ apt.update() apt.add_package("zsh") apt.add_package(["vim", "htop", "wget"]) -except PackageNotFoundError: - logger.error("a specified package not found in package cache or on system") except PackageError as e: logger.error("could not install package. Reason: %s", e.message) ```` +The convenience methods don't raise `PackageNotFoundError`. If any packages aren't found in +the cache, `apt.add_package` raises `PackageError` with a message 'Failed to install +packages: foo, bar'. + To find details of a specific package: ```python @@ -160,11 +162,15 @@ def message(self): class PackageError(Error): - """Raised when there's an error installing or removing a package.""" + """Raised when there's an error installing or removing a package. + + Additionally, `apt.add_package` raises `PackageError` if any packages aren't found in + the cache. + """ class PackageNotFoundError(Error): - """Raised when a requested package is not known to the system.""" + """Raised by `DebianPackage` methods if a requested package is not found.""" class PackageState(Enum): @@ -779,8 +785,8 @@ def add_package( Raises: TypeError if no package name is given, or explicit version is set for multiple packages - PackageNotFoundError if the package is not in the cache. - PackageError if packages fail to install + PackageError: if packages fail to install, including if any packages aren't found in the + cache """ cache_refreshed = False if update_cache: