Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/charms/operator_libs_linux/v0/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,7 +133,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"]

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down