Skip to content

Commit

Permalink
Include additional information in PartitioningError
Browse files Browse the repository at this point in the history
The generic 'Unable to allocate requested partition scheme' is not
very helpful, we should try to include additional information if
possible.
  • Loading branch information
vojtechtrefny committed Jan 22, 2025
1 parent 28da4a0 commit 529ab4e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions blivet/partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 529ab4e

Please sign in to comment.