src: make exception messages more contextual and explicit

Provide more information in exception messages as those are the
source of the logging messages. Add information about paths, files
or configuration related to the operation associated to the
exception.
master
Alejandro Sirgo Rica 2024-03-18 20:30:27 +01:00 committed by lupoDharkael
parent 8741b2e272
commit 049b7a5a2b
7 changed files with 9 additions and 9 deletions

View File

@ -270,7 +270,7 @@ class OgLiveOperations:
if not mount_mkdir(partdev, mountpoint): if not mount_mkdir(partdev, mountpoint):
raise RuntimeError(f'Error mounting {partdev} at {mountpoint}') raise RuntimeError(f'Error mounting {partdev} at {mountpoint}')
if not os.path.ismount(mountpoint): if not os.path.ismount(mountpoint):
raise RuntimeError('Invalid mountpoint for software inventory') raise RuntimeError(f'Invalid mountpoint {mountpoint} for software inventory')
self._restartBrowser(self._url_log) self._restartBrowser(self._url_log)
pkgset = get_package_set(mountpoint) pkgset = get_package_set(mountpoint)

View File

@ -54,4 +54,4 @@ def get_parttype(cxt, ptype_str):
elif cxt.label.name == 'gpt': elif cxt.label.name == 'gpt':
return get_gpt_parttype(cxt, ptype_str) return get_gpt_parttype(cxt, ptype_str)
else: else:
raise RuntimeError('BUG: Invalid partition label') raise RuntimeError(f'Invalid partition label \'{cxt.label.name}\'')

View File

@ -125,7 +125,7 @@ def configure_logging(mode, level):
elif mode == 'live': elif mode == 'live':
logconfig = _default_logging_live() logconfig = _default_logging_live()
else: else:
raise ValueError(f'Error: Mode {mode} not supported') raise ValueError(f'Logging mode {mode} not supported')
logconfig['loggers']['']['level'] = level logconfig['loggers']['']['level'] = level

View File

@ -263,7 +263,7 @@ class ogRest():
from src.windows.ogOperations import OgWindowsOperations from src.windows.ogOperations import OgWindowsOperations
self.operations = OgWindowsOperations() self.operations = OgWindowsOperations()
else: else:
raise ValueError('Mode not supported.') raise ValueError(f'Ogrest mode \'{self.mode}\'not supported')
def send_internal_server_error(self, client, exc=None): def send_internal_server_error(self, client, exc=None):
if isinstance(exc, AssertionError): if isinstance(exc, AssertionError):

View File

@ -130,6 +130,6 @@ def boot_os_at(disk, part):
elif not is_uefi and os_family == OSFamily.LINUX: elif not is_uefi and os_family == OSFamily.LINUX:
_boot_bios_linux(disk, part, mountpoint) _boot_bios_linux(disk, part, mountpoint)
else: else:
raise RuntimeError('Unknown OS family') raise RuntimeError(f'Unknown OS family {os_family}')
finally: finally:
umount(mountpoint) umount(mountpoint)

View File

@ -55,7 +55,7 @@ class HardwareInventory():
def add_element(self, elem): def add_element(self, elem):
if elem.type not in HardwareType: if elem.type not in HardwareType:
raise ValueError('Unsupported hardware type') raise ValueError(f'Unsupported hardware type, received {elem.type}')
if not elem.name: if not elem.name:
raise ValueError('Empty hardware element name') raise ValueError('Empty hardware element name')
self.elements.append(elem) self.elements.append(elem)
@ -250,7 +250,7 @@ def legacy_hardware_element(element):
represented as "vga=Foo" represented as "vga=Foo"
""" """
if type(element) is not HardwareElement: if type(element) is not HardwareElement:
raise TypeError('Invalid type') raise TypeError('Invalid hardware element type')
elif element.type is HardwareType.MULTIMEDIA: elif element.type is HardwareType.MULTIMEDIA:
nemonic = 'mul' nemonic = 'mul'
elif element.type is HardwareType.BOOTMODE: elif element.type is HardwareType.BOOTMODE:
@ -297,7 +297,7 @@ def get_hardware_inventory():
if type(j) is list: if type(j) is list:
root = j[0] root = j[0]
if type(root) is not dict: if type(root) is not dict:
raise ValueError('Unvalid lshw json output') raise ValueError('Invalid lshw json output')
inventory = HardwareInventory() inventory = HardwareInventory()
_fill_computer_model(inventory, root) _fill_computer_model(inventory, root)

View File

@ -174,7 +174,7 @@ def ogChangeRepo(ip, smb_user='opengnsys', smb_pass='og'):
try: try:
ipaddr = ipaddress.ip_address(ip) ipaddr = ipaddress.ip_address(ip)
except ValueError as e: except ValueError as e:
raise ValueError('Invalid ip address') raise ValueError(f'Invalid IP address {ip} received')
mounted = False mounted = False
with open('/etc/mtab') as f: with open('/etc/mtab') as f: