summaryrefslogtreecommitdiffstats
path: root/src/utils/fs.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-03-18 14:17:12 +0100
committerlupoDharkael <izhe@hotmail.es>2024-03-21 10:29:57 +0100
commit2a4ce65a20b41a670b274cb473d46e62b4f3c913 (patch)
tree947c45ef966b226cbb980beabdc964184aa81a02 /src/utils/fs.py
parent0cbf16461e05bc5f15d3436763667b1d34869826 (diff)
src: centralize error logging into send_internal_server_error
Use only the exception messages as the main resource for error messages. The previous error code had string duplication in the form of: logging.error('msg here') raise Exception('msg here') That approach also has the downside of having log duplication as it had the local logging.err() and a global logging.exception() inside send_internal_server_error capturing the exception message. The actual code only requires raising an exception with a proper error message. Improve exception messages to give more error context. Log every AssertionError as a backtrace. Use the 'raise Exception from e' syntax to modify the a previously raised exception 'e' into an exception with aditional context or different type. This also prevents the message that warns about newer exceptions being launch after an initial exception.
Diffstat (limited to 'src/utils/fs.py')
-rw-r--r--src/utils/fs.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/utils/fs.py b/src/utils/fs.py
index 69b4789..1015754 100644
--- a/src/utils/fs.py
+++ b/src/utils/fs.py
@@ -150,14 +150,12 @@ def mkfs(fs, disk, partition, label=None):
}
if fs not in fsdict:
- logging.error(f'mkfs fails, unsupported target filesystem {fs}')
- raise ValueError(f'Unsupported target filesystem {fs}')
+ raise ValueError(f'mkfs failed, unsupported target filesystem {fs}')
try:
partdev = get_partition_device(disk, partition)
except ValueError as e:
- logging.error(f'mkfs aborted, invalid partition.')
- raise e
+ raise ValueError(f'mkfs aborted: {e}') from e
fsdict[fs](partdev, label)
@@ -253,13 +251,11 @@ def _reduce_ntfsresize(partdev):
data_split = output_data.split(pattern)
# If we fail to match pattern in the split then data_split will contain [output_data]
if len(data_split) == 1:
- logging.error(f'nfsresize: failed to find: "{pattern}"')
- raise ValueError(f'nfsresize: failed to find: "{pattern}"')
+ raise ValueError(f'nfsresize: failed to find: {pattern}')
value_str = data_split[1].split(' ')[0]
if not value_str.isdigit() or value_str.startswith('-'):
- logging.error(f'nfsresize: failed to parse numeric value at "{pattern}"')
- raise ValueError(f'nfsresize: failed to parse numeric value at "{pattern}"')
+ raise ValueError(f'nfsresize: failed to parse numeric value at {pattern}')
return int(value_str)
try: