Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / controller / python / chip / exceptions / __init__.py
1 #
2 #    Copyright (c) 2021 Project CHIP Authors
3 #    All rights reserved.
4 #
5 #    Licensed under the Apache License, Version 2.0 (the "License");
6 #    you may not use this file except in compliance with the License.
7 #    You may obtain a copy of the License at
8 #
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #    Unless required by applicable law or agreed to in writing, software
12 #    distributed under the License is distributed on an "AS IS" BASIS,
13 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #    See the License for the specific language governing permissions and
15 #    limitations under the License.
16 #
17
18 __all__ = [
19     "ChipStackException",
20     "ChipStackError",
21     "DeviceError",
22     "InvalidArgumentCount",
23     "InvalidArgumentType",
24     "UnknownAttribute",
25     "UnknownCluster",
26     "UnknownCommand",
27 ]
28
29
30 class ChipStackException(Exception):
31     pass
32
33
34 class ChipStackError(ChipStackException):
35     def __init__(self, err, msg=None):
36         self.err = err
37         self.msg = msg if msg else "Chip Stack Error %d" % err
38
39     def __str__(self):
40         return self.msg
41
42
43 class DeviceError(ChipStackException):
44     def __init__(self, profileId, statusCode, systemErrorCode, msg=None):
45         self.profileId = profileId
46         self.statusCode = statusCode
47         self.systemErrorCode = systemErrorCode
48         if not msg:
49             self.msg = "[ %08X:%d ]" % (profileId, statusCode)
50             if systemErrorCode:
51                 self.msg += " (system err %d)" % systemErrorCode
52         else:
53             self.msg = msg
54
55     def __str__(self):
56         return "Device Error: " + self.msg
57
58
59 class ClusterError(ChipStackException):
60     pass
61
62
63 class InvalidArgumentCount(ChipStackException):
64     def __init__(self, expect: int, given: int):
65         self.expect = expect
66         self.given = given
67
68     def __str__(self):
69         return "InvalidArgumentCount: Expect {}, {} given".format(self.expect, self.given)
70
71
72 class InvalidArgumentType(ChipStackException):
73     def __init__(self, expect: type, given: type, name: str):
74         self.expect = expect
75         self.given = given
76         self.argname = name
77
78     def __str__(self):
79         return "InvalidArgumentType: Argument {} should be {}, {} got".format(self.argname, self.expect, self.given)
80
81
82 class UnknownCluster(ClusterError):
83     def __init__(self, cluster: str):
84         self.cluster = cluster
85
86     def __str__(self):
87         return "UnknownCluster: {}".format(self.cluster)
88
89
90 class UnknownCommand(ClusterError):
91     def __init__(self, cluster: str, command: str):
92         self.cluster = cluster
93         self.command = command
94
95     def __str__(self):
96         return "UnknownCommand: cluster: {}, command: {}".format(self.cluster, self.command)
97
98
99 class UnknownAttribute(ClusterError):
100     def __init__(self, cluster: str, attribute: str):
101         self.cluster = cluster
102         self.attribute = attribute
103
104     def __str__(self):
105         return "UnknownAttribute: cluster: {}, attribute: {}".format(self.cluster, self.attribute)