Skip to content

Commit

Permalink
fix: Transmute error type in validation
Browse files Browse the repository at this point in the history
Allowing pydantic to properly handle it

> validators should either return the parsed value or raise a ValueError or AssertionError
https://docs.pydantic.dev/latest/concepts/validators/#field-validators
  • Loading branch information
alecandido authored Dec 7, 2024
1 parent 2146782 commit bda1956
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/qibolab/_core/instruments/qblox/ast_.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class Register(Model):
@model_validator(mode="before")
@classmethod
def load(cls, data: Any) -> Any:
assert data[0] == "R"
try:
assert data[0] == "R"
except TypeError:
raise ValueError("Register representation is not a string")
num = int(data[1:])
assert 0 <= num < 64
return {"number": num}
Expand Down

0 comments on commit bda1956

Please sign in to comment.