]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
doc/_ext: use raise .. from
authorKefu Chai <tchaikov@gmail.com>
Wed, 25 Jun 2025 00:14:54 +0000 (08:14 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 25 Jun 2025 00:24:19 +0000 (08:24 +0800)
Use raise-from statement to preserve the root cause of the exception,
this helps to provide more context for debugging when the exception
is raised.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
doc/_ext/ceph_confval.py

index c5e212173f18b9870d42db7a57434ff88f85227b..f515732bcbb610c38d8c15d6fc5d1c1a8e660a80 100644 (file)
@@ -84,7 +84,7 @@ TEMPLATE = '''
 def eval_size(value) -> int:
     try:
         return int(value)
-    except ValueError:
+    except ValueError as ex:
         times = dict(_K=1 << 10,
                      _M=1 << 20,
                      _G=1 << 30,
@@ -92,7 +92,7 @@ def eval_size(value) -> int:
         for unit, m in times.items():
             if value.endswith(unit):
                 return int(value[:-len(unit)]) * m
-        raise ValueError(f'unknown value: {value}')
+        raise ValueError(f'unknown value: {value}') from ex
 
 
 def readable_duration(value: str, typ: str) -> str:
@@ -105,7 +105,7 @@ def readable_duration(value: str, typ: str) -> str:
             return str(float(value))
         else:
             return str(int(value))
-    except ValueError:
+    except ValueError as ex:
         times = dict(_min=['minute', 'minutes'],
                      _hr=['hour', 'hours'],
                      _day=['day', 'days'])
@@ -114,7 +114,7 @@ def readable_duration(value: str, typ: str) -> str:
                 v = int(value[:-len(unit)])
                 postfix = readables[0 if v == 1 else 1]
                 return f'{v} {postfix}'
-        raise ValueError(f'unknown value: {value}')
+        raise ValueError(f'unknown value: {value}') from ex
 
 
 def do_plain_num(value: str, typ: str) -> str: