Skip to content

Commit 3f62102

Browse files
committed
Fix corner case: serializing a valid type with an invalid value
1 parent 99658f5 commit 3f62102

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

tests/test_commands.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ def test_command_param_binding():
178178
with pytest.raises(ValueError):
179179
c.UtilCommands.TimeAlive.Rsp(Seconds=b"asd")
180180

181+
# Valid type but invalid value
182+
with pytest.raises(ValueError):
183+
c.UtilCommands.SetPreConfigKey.Req(PreConfigKey=t.KeyData([1, 2, 3]))
184+
181185
# Coerced numerical type
182186
a = c.UtilCommands.TimeAlive.Rsp(Seconds=12)
183187
b = c.UtilCommands.TimeAlive.Rsp(Seconds=t.uint32_t(12))

zigpy_znp/types/commands.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,13 @@ def __init__(self, *, partial=False, **params):
363363
f"type {param.type}, got {type(value)}"
364364
)
365365

366-
try:
367-
# XXX: Break early if a type cannot be serialized
368-
value.serialize()
369-
except Exception as e:
370-
raise ValueError(
371-
f"Invalid parameter value: {param.name}={value!r}"
372-
) from e
366+
try:
367+
# XXX: Break early if a type cannot be serialized
368+
value.serialize()
369+
except Exception as e:
370+
raise ValueError(
371+
f"Invalid parameter value: {param.name}={value!r}"
372+
) from e
373373

374374
bound_params[param.name] = (param, value)
375375

0 commit comments

Comments
 (0)