Skip to content

Commit 9249e2e

Browse files
committed
Log decimal conversion issues
Signed-off-by: cwasicki <[email protected]>
1 parent f868ca7 commit 9249e2e

File tree

1 file changed

+19
-5
lines changed
  • src/frequenz/client/electricity_trading

1 file changed

+19
-5
lines changed

src/frequenz/client/electricity_trading/_types.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,18 @@ def from_pb(cls, price: price_pb2.Price) -> Self:
9999
100100
Returns:
101101
Price object corresponding to the protobuf message.
102+
103+
Raises:
104+
Exception: If an error occurs during conversion.
102105
"""
103-
return cls(
104-
amount=Decimal(price.amount.value),
105-
currency=Currency.from_pb(price.currency),
106-
)
106+
try:
107+
return cls(
108+
amount=Decimal(price.amount.value),
109+
currency=Currency.from_pb(price.currency),
110+
)
111+
except Exception as e:
112+
_logger.error("Error converting price `%s`: %s", price, e)
113+
raise e
107114

108115
def to_pb(self) -> price_pb2.Price:
109116
"""Convert a Price object to protobuf Price.
@@ -139,8 +146,15 @@ def from_pb(cls, power: power_pb2.Power) -> Self:
139146
140147
Returns:
141148
Power object corresponding to the protobuf message.
149+
150+
Raises:
151+
Exception: If an error occurs during conversion.
142152
"""
143-
return cls(mw=Decimal(power.mw.value))
153+
try:
154+
return cls(mw=Decimal(power.mw.value))
155+
except Exception as e:
156+
_logger.error("Error converting power `%s`: %s", power, e)
157+
raise e
144158

145159
def to_pb(self) -> power_pb2.Power:
146160
"""Convert a Power object to protobuf Power.

0 commit comments

Comments
 (0)