Skip to content

Commit 5eb87c0

Browse files
committed
Raise an error if someone is using an incorrect suffix
1 parent 95a85b1 commit 5eb87c0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

synapse/config/_base.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ def parse_duration(value: Union[str, int]) -> int:
221221
The number of milliseconds in the duration.
222222
223223
Raises:
224-
TypeError, if given something other than an integer or a string
224+
TypeError: if given something other than an integer or a string, or the
225+
duration is using an incorrect suffix.
225226
ValueError: if given a string not of the form described above.
226227
"""
227228
if type(value) is int: # noqa: E721
@@ -246,6 +247,15 @@ def parse_duration(value: Union[str, int]) -> int:
246247
if suffix in sizes:
247248
value = value[:-1]
248249
size = sizes[suffix]
250+
elif suffix.isdigit():
251+
# No suffix is treated as milliseconds.
252+
value = value
253+
size = 1
254+
else:
255+
raise TypeError(
256+
f"Bad duration suffix {value} (expected no suffix or one of these suffixes: {sizes.keys()})"
257+
)
258+
249259
return int(value) * size
250260
else:
251261
raise TypeError(f"Bad duration {value!r}")

0 commit comments

Comments
 (0)