Skip to content

Commit 999dbae

Browse files
committed
Add specific errors for different gRPC statuses
This makes error handling more pythonic, as one can now just catch the exception type one is interested in, without having to do a second-level matching using the status. It also helps avoiding to expose the grpclib classes to the user. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 77a3770 commit 999dbae

File tree

2 files changed

+560
-1
lines changed

2 files changed

+560
-1
lines changed

src/frequenz/client/microgrid/__init__.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,26 @@
2727
)
2828
from ._component_states import EVChargerCableState, EVChargerComponentState
2929
from ._connection import Connection
30-
from ._exception import ClientError
30+
from ._exception import (
31+
ClientError,
32+
DataLoss,
33+
EntityAlreadyExists,
34+
EntityNotFound,
35+
GrpcStatusError,
36+
InternalError,
37+
InvalidArgument,
38+
OperationAborted,
39+
OperationCancelled,
40+
OperationNotImplemented,
41+
OperationOutOfRange,
42+
OperationPreconditionFailed,
43+
OperationTimedOut,
44+
OperationUnauthenticated,
45+
PermissionDenied,
46+
ResourceExhausted,
47+
ServiceUnavailable,
48+
UnknownError,
49+
)
3150
from ._metadata import Location, Metadata
3251

3352
__all__ = [
@@ -41,14 +60,31 @@
4160
"ComponentMetricId",
4261
"ComponentType",
4362
"Connection",
63+
"DataLoss",
4464
"EVChargerCableState",
4565
"EVChargerComponentState",
4666
"EVChargerData",
67+
"EntityAlreadyExists",
68+
"EntityNotFound",
4769
"Fuse",
4870
"GridMetadata",
71+
"GrpcStatusError",
72+
"InternalError",
73+
"InvalidArgument",
4974
"InverterData",
5075
"InverterType",
5176
"Location",
5277
"Metadata",
5378
"MeterData",
79+
"OperationAborted",
80+
"OperationCancelled",
81+
"OperationNotImplemented",
82+
"OperationOutOfRange",
83+
"OperationPreconditionFailed",
84+
"OperationTimedOut",
85+
"OperationUnauthenticated",
86+
"PermissionDenied",
87+
"ResourceExhausted",
88+
"ServiceUnavailable",
89+
"UnknownError",
5490
]

0 commit comments

Comments
 (0)