diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-04-02 12:51:34 +0200 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-04-03 13:31:10 +0200 |
commit | dfde363aa63ad3e7967da49f4ab599399b89e7f8 (patch) | |
tree | 051f1f1d1e3c8e07ae12af2bfb35174be18f1201 /src/live/parttypes.py | |
parent | c5ccc3c7e201beccf8eb3d329e478bb33b34d43e (diff) |
src: log backtrace in unhandled error cases
Log an error message in known error cases and log a backtrace
otherwise.
Define a new error type OgError to be used in all the 'raise'
blocks to define the error message to log. The exception
propagates until it reaches send_internal_server_error() where
the exception type is checked. If the type is OgError we log
the exception message. Logs the backtrace for other types.
The initial error implementation printed a backtrace everytime
an error ocurred. The next iteration changed it to only print
a backtrace in a very particular case but ended up omiting too
much information such as syntax errors or unknown error context.
The actual implementation only logs the cases we already cover in
the codebase and logs a bracktrace in the others, enabling a
better debugging experience.
Diffstat (limited to 'src/live/parttypes.py')
-rw-r--r-- | src/live/parttypes.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/live/parttypes.py b/src/live/parttypes.py index b4c1793..d8db8f6 100644 --- a/src/live/parttypes.py +++ b/src/live/parttypes.py @@ -7,6 +7,7 @@ # (at your option) any later version. import fdisk +from src.log import OgError GPT_PARTTYPES = { 'LINUX-SWAP': '0657FD6D-A4AB-43C4-84E5-0933C84B4F4F', @@ -43,15 +44,15 @@ def get_gpt_parttype(cxt, ptype_str): def get_parttype(cxt, ptype_str): if not cxt: - raise RuntimeError('No libfdisk context') + raise OgError('No libfdisk context') if not cxt.label or cxt.label.name not in ['dos', 'gpt']: - raise RuntimeError('Unknown libfdisk label') + raise OgError('Unknown libfdisk label') if type(ptype_str) != str: - raise RuntimeError('Invalid partition type') + raise OgError('Invalid partition type') if cxt.label.name == 'dos': return get_dos_parttype(cxt, ptype_str) elif cxt.label.name == 'gpt': return get_gpt_parttype(cxt, ptype_str) else: - raise RuntimeError(f'Invalid partition label \'{cxt.label.name}\'') + raise OgError(f'Invalid partition label \'{cxt.label.name}\'') |