-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexceptions.py
More file actions
193 lines (112 loc) · 5.19 KB
/
exceptions.py
File metadata and controls
193 lines (112 loc) · 5.19 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from grpc import RpcError
class SnetSDKError(Exception):
"""Base SNET SDK exception class"""
pass
# ==================== Blockchain interaction Errors ====================
class ContractError(SnetSDKError):
pass
class TransactionError(ContractError):
pass
class TransactionTimeoutError(TransactionError):
def __init__(self, tx_hash: str, timeout: int):
super().__init__(f"Transaction {tx_hash} was not mined within {timeout} seconds!")
class TransactionRevertedError(TransactionError):
def __init__(self, tx_hash: str):
super().__init__(f"Transaction {tx_hash} failed and was reverted by the network!")
class EventNotFoundError(TransactionError):
def __init__(self, tx_hash: str, event_name: str):
super().__init__(
f"Transaction {tx_hash} succeeded, but the expected event '{event_name}' was not emitted."
)
class RegistryContractError(ValueError, ContractError):
pass
class OrganizationNotFoundError(RegistryContractError):
def __init__(self, org_id: str):
super().__init__(f"Organization with org_id={org_id} doesn't exist!")
class ServiceNotFoundError(RegistryContractError):
def __init__(self, org_id: str, service_id: str):
super().__init__(f"Service with org_id={org_id} service_id={service_id} doesn't exist!")
class UnauthorizedCallerError(RegistryContractError):
pass
class UnauthorizedOrgMemberError(UnauthorizedCallerError):
def __init__(self, org_id: str, address: str):
super().__init__(
f"Address {address} isn't an owner or a member of the organization {org_id}!"
)
class UnauthorizedOrgOwnerError(UnauthorizedCallerError):
def __init__(self, org_id: str, address: str):
super().__init__(f"Address {address} isn't an owner of the organization {org_id}!")
class IncorrectWalletAddressError(RegistryContractError):
def __init__(self, address: str):
super().__init__(f"Address {address} is not a correct Ethereum address!")
# ==================== Metadata Errors ====================
class MetadataMismatchError(ValueError, SnetSDKError):
pass
class ServiceMetadataMismatchError(MetadataMismatchError):
pass
class OrganizationMetadataMismatchError(MetadataMismatchError):
pass
# ==================== Storage Provider Errors ====================
class StorageProviderError(SnetSDKError):
pass
class UnsupportedStorageTypeError(ValueError, StorageProviderError):
def __init__(self, storage_type: str):
super().__init__(f"Unsupported storage type: {storage_type}!")
class LighthouseError(StorageProviderError):
def __init__(self):
super().__init__(
"Lighthouse internal error! Most likely, you did not specify LIGHTHOUSE_TOKEN in the config or it expired."
)
class IPFSError(StorageProviderError):
pass
class IPFSHashMismatchError(IPFSError):
def __init__(self):
super().__init__("IPFS hash mismatch with data")
class IPFSHashCheckError(IPFSError):
def __init__(self):
super().__init__("IPFS hash integrity check failed!")
class PublishProtoError(ValueError, StorageProviderError):
pass
class WrongDirectoryError(PublishProtoError):
def __init__(self, dir_path: str):
super().__init__(f"{dir_path} isn't a directory or it doesn't exist!")
class ProtoFilesNotFoundError(PublishProtoError):
def __init__(self, dir_path: str):
super().__init__(f"Cannot find any .proto file in {dir_path}!")
class ExtractingProtoError(ValueError, StorageProviderError):
pass
# ==================== Training Errors ====================
class TrainingError(SnetSDKError):
pass
class WrongDatasetError(TrainingError):
def __init__(self, errors: list[str]):
self.errors = errors
exception_msg = "Dataset check failed:\n"
for check in errors:
exception_msg += f"\t{check}\n"
super().__init__(exception_msg)
class WrongMethodError(ValueError, TrainingError):
def __init__(self, method_name: str):
super().__init__(f"Method with name {method_name} not found!")
class NoTrainingError(ValueError, TrainingError):
def __init__(self, org_id: str, service_id: str):
super().__init__(
f"Training is not implemented for the service with org_id={org_id} and service_id={service_id}!"
)
class GRPCError(RpcError, TrainingError):
def __init__(self, error: RpcError):
super().__init__(f"An error occurred during the grpc call: {error}.")
class NoSuchModelError(ValueError, TrainingError):
def __init__(self, model_id: str):
super().__init__(f"Model with id {model_id} not found!")
# ==================== Service Client Errors ====================
class ServiceClientError(SnetSDKError):
pass
class NoGroupsFoundError(ServiceClientError):
def __init__(self, org_id: str, service_id: str):
super().__init__(f"Service with org_id={org_id} service_id={service_id} has no groups!")
class GroupNotFoundError(ServiceClientError):
def __init__(self, org_id: str, service_id: str, group_name: str):
super().__init__(
f"Service with org_id={org_id} service_id={service_id} has no group with group_name={group_name}!"
)