From 529ab4ea51e072b8d2c4ec0815f4b866d5414a1c Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 22 Jan 2025 13:16:43 +0100 Subject: [PATCH] Include additional information in PartitioningError The generic 'Unable to allocate requested partition scheme' is not very helpful, we should try to include additional information if possible. --- blivet/partitioning.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/blivet/partitioning.py b/blivet/partitioning.py index 421d5329b..b1778c055 100644 --- a/blivet/partitioning.py +++ b/blivet/partitioning.py @@ -34,7 +34,7 @@ from .flags import flags from .devices import Device, PartitionDevice, device_path_to_name from .size import Size -from .i18n import _ +from .i18n import _, N_ from .util import compare import logging @@ -763,6 +763,7 @@ def allocate_partitions(storage, disks, partitions, freespace, boot_disk=None): part_type = None growth = 0 # in sectors # loop through disks + errors = set() for _disk in req_disks: try: disklabel = disklabels[_disk.path] @@ -797,7 +798,9 @@ def allocate_partitions(storage, disks, partitions, freespace, boot_disk=None): new_part_type = get_next_partition_type(disklabel.parted_disk) if new_part_type is None: # can't allocate any more partitions on this disk - log.debug("no free partition slots on %s", _disk.name) + msg = N_("no free partition slots on %s") % _disk.name + log.debug(msg) + errors.add(_(msg)) continue if _part.req_primary and new_part_type != parted.PARTITION_NORMAL: @@ -808,7 +811,9 @@ def allocate_partitions(storage, disks, partitions, freespace, boot_disk=None): new_part_type = parted.PARTITION_NORMAL else: # we need a primary slot and none are free on this disk - log.debug("no primary slots available on %s", _disk.name) + msg = N_("no primary partition slots available on %s") % _disk.name + log.debug(msg) + errors.add(_(msg)) continue elif _part.req_part_type is not None and \ new_part_type != _part.req_part_type: @@ -968,7 +973,11 @@ def allocate_partitions(storage, disks, partitions, freespace, boot_disk=None): break if free is None: - raise PartitioningError(_("Unable to allocate requested partition scheme.")) + if not errors: + msg = _("Unable to allocate requested partition scheme.") + else: + msg = _("Unable to allocate requested partition scheme:\n%s") % "\n".join(errors) + raise PartitioningError(msg) _disk = use_disk disklabel = _disk.format