@@ -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
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
144158
145159 def to_pb (self ) -> power_pb2 .Power :
146160 """Convert a Power object to protobuf Power.
@@ -959,42 +973,51 @@ def from_pb(cls, order: electricity_trading_pb2.Order) -> Self:
959973
960974 Returns:
961975 Order object corresponding to the protobuf message.
962- """
963- return cls (
964- delivery_area = DeliveryArea .from_pb (order .delivery_area ),
965- delivery_period = DeliveryPeriod .from_pb (order .delivery_period ),
966- type = OrderType .from_pb (order .type ),
967- side = MarketSide .from_pb (order .side ),
968- price = Price .from_pb (order .price ),
969- quantity = Power .from_pb (order .quantity ),
970- stop_price = (
971- Price .from_pb (order .stop_price )
972- if order .HasField ("stop_price" )
973- else None
974- ),
975- peak_price_delta = (
976- Price .from_pb (order .peak_price_delta )
977- if order .HasField ("peak_price_delta" )
978- else None
979- ),
980- display_quantity = (
981- Power .from_pb (order .display_quantity )
982- if order .HasField ("display_quantity" )
983- else None
984- ),
985- execution_option = (
986- OrderExecutionOption .from_pb (order .execution_option )
987- if order .HasField ("execution_option" )
988- else None
989- ),
990- valid_until = (
991- order .valid_until .ToDatetime (tzinfo = timezone .utc )
992- if order .HasField ("valid_until" )
993- else None
994- ),
995- payload = json_format .MessageToDict (order .payload ) if order .payload else None ,
996- tag = order .tag if order .tag else None ,
997- )
976+
977+ Raises:
978+ Exception: If an error occurs during conversion.
979+ """
980+ try :
981+ return cls (
982+ delivery_area = DeliveryArea .from_pb (order .delivery_area ),
983+ delivery_period = DeliveryPeriod .from_pb (order .delivery_period ),
984+ type = OrderType .from_pb (order .type ),
985+ side = MarketSide .from_pb (order .side ),
986+ price = Price .from_pb (order .price ),
987+ quantity = Power .from_pb (order .quantity ),
988+ stop_price = (
989+ Price .from_pb (order .stop_price )
990+ if order .HasField ("stop_price" )
991+ else None
992+ ),
993+ peak_price_delta = (
994+ Price .from_pb (order .peak_price_delta )
995+ if order .HasField ("peak_price_delta" )
996+ else None
997+ ),
998+ display_quantity = (
999+ Power .from_pb (order .display_quantity )
1000+ if order .HasField ("display_quantity" )
1001+ else None
1002+ ),
1003+ execution_option = (
1004+ OrderExecutionOption .from_pb (order .execution_option )
1005+ if order .HasField ("execution_option" )
1006+ else None
1007+ ),
1008+ valid_until = (
1009+ order .valid_until .ToDatetime (tzinfo = timezone .utc )
1010+ if order .HasField ("valid_until" )
1011+ else None
1012+ ),
1013+ payload = (
1014+ json_format .MessageToDict (order .payload ) if order .payload else None
1015+ ),
1016+ tag = order .tag if order .tag else None ,
1017+ )
1018+ except Exception as e :
1019+ _logger .error ("Error converting order `%s`: %s" , order , e )
1020+ raise
9981021
9991022 def to_pb (self ) -> electricity_trading_pb2 .Order :
10001023 """
0 commit comments