-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy patherrors.py
94 lines (50 loc) · 2.1 KB
/
errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Matter Exceptions."""
from __future__ import annotations
# mapping from error_code to Exception class
ERROR_MAP: dict[int, type] = {}
class MatterError(Exception):
"""Generic Matter exception."""
error_code = 0
def __init_subclass__(cls, *args, **kwargs) -> None: # type: ignore[no-untyped-def]
"""Register a subclass."""
super().__init_subclass__(*args, **kwargs)
ERROR_MAP[cls.error_code] = cls
class UnknownError(MatterError):
"""Error raised when there an unknown/invalid command is requested."""
error_code = 0 # to map all generic errors
class NodeCommissionFailed(MatterError):
"""Error raised when interview of a device failed."""
error_code = 1
class NodeInterviewFailed(MatterError):
"""Error raised when interview of a device failed."""
error_code = 2
class NodeNotReady(MatterError):
"""Error raised when performing action on node that has not been fully added."""
error_code = 3
class NodeNotResolving(MatterError):
"""Error raised when no CASE session could be established."""
error_code = 4
class NodeNotExists(MatterError):
"""Error raised when performing action on node that does not exist."""
error_code = 5
class VersionMismatch(MatterError):
"""Issue raised when SDK version mismatches."""
error_code = 6
class SDKStackError(MatterError):
"""Generic SDK stack error."""
error_code = 7
class InvalidArguments(MatterError):
"""Error raised when there are invalid arguments provided for a command."""
error_code = 8
class InvalidCommand(MatterError):
"""Error raised when there an unknown/invalid command is requested."""
error_code = 9
class UpdateCheckError(MatterError):
"""Error raised when there was an error during searching for updates."""
error_code = 10
class UpdateError(MatterError):
"""Error raised when there was an error during applying updates."""
error_code = 11
def exception_from_error_code(error_code: int) -> type[MatterError]:
"""Return correct Exception class from error_code."""
return ERROR_MAP.get(error_code, MatterError)