@@ -15,6 +15,7 @@ class DiracError(RuntimeError):
15
15
16
16
def __init__ (self , detail : str = "Unknown" ):
17
17
self .detail = detail
18
+ super ().__init__ (detail )
18
19
19
20
20
21
class AuthorizationError (DiracError ): ...
@@ -53,19 +54,19 @@ class InvalidQueryError(DiracError):
53
54
54
55
55
56
class TokenNotFoundError (DiracError ):
56
- def __init__ (self , jti : str , detail : str | None = None ):
57
+ def __init__ (self , jti : str , detail : str = "" ):
57
58
self .jti : str = jti
58
59
super ().__init__ (f"Token { jti } not found" + (f" ({ detail } )" if detail else "" ))
59
60
60
61
61
62
class JobNotFoundError (DiracError ):
62
- def __init__ (self , job_id : int , detail : str | None = None ):
63
+ def __init__ (self , job_id : int , detail : str = "" ):
63
64
self .job_id : int = job_id
64
65
super ().__init__ (f"Job { job_id } not found" + (f" ({ detail } )" if detail else "" ))
65
66
66
67
67
68
class SandboxNotFoundError (DiracError ):
68
- def __init__ (self , pfn : str , se_name : str , detail : str | None = None ):
69
+ def __init__ (self , pfn : str , se_name : str , detail : str = "" ):
69
70
self .pfn : str = pfn
70
71
self .se_name : str = se_name
71
72
super ().__init__ (
@@ -75,7 +76,7 @@ def __init__(self, pfn: str, se_name: str, detail: str | None = None):
75
76
76
77
77
78
class SandboxAlreadyAssignedError (DiracError ):
78
- def __init__ (self , pfn : str , se_name : str , detail : str | None = None ):
79
+ def __init__ (self , pfn : str , se_name : str , detail : str = "" ):
79
80
self .pfn : str = pfn
80
81
self .se_name : str = se_name
81
82
super ().__init__ (
@@ -85,7 +86,7 @@ def __init__(self, pfn: str, se_name: str, detail: str | None = None):
85
86
86
87
87
88
class SandboxAlreadyInsertedError (DiracError ):
88
- def __init__ (self , pfn : str , se_name : str , detail : str | None = None ):
89
+ def __init__ (self , pfn : str , se_name : str , detail : str = "" ):
89
90
self .pfn : str = pfn
90
91
self .se_name : str = se_name
91
92
super ().__init__ (
@@ -95,7 +96,7 @@ def __init__(self, pfn: str, se_name: str, detail: str | None = None):
95
96
96
97
97
98
class JobError (DiracError ):
98
- def __init__ (self , job_id , detail : str | None = None ):
99
+ def __init__ (self , job_id , detail : str = "" ):
99
100
self .job_id : int = job_id
100
101
super ().__init__ (
101
102
f"Error concerning job { job_id } " + (f" ({ detail } )" if detail else "" )
@@ -106,81 +107,69 @@ class NotReadyError(DiracError):
106
107
"""Tried to access a value which is asynchronously loaded but not yet available."""
107
108
108
109
109
- class GenericError ( Exception ):
110
- head : str = "Error"
111
- tail : str = ""
110
+ class DiracFormattedError ( DiracError ):
111
+ # TODO: Refactor?
112
+ pattern = "Error %s "
112
113
113
- def __init__ (self , data : dict [str , str ], detail : str | None = None ):
114
+ def __init__ (self , data : dict [str , str ], detail : str = "" ):
114
115
self .data = data
115
- self .detail = detail
116
116
117
117
parts = [f"({ key } : { value } )" for key , value in data .items ()]
118
- message = f" { self . head } { ' ' .join (parts )} { self . tail } "
118
+ message = type ( self ). pattern % ( " " .join (parts ))
119
119
if detail :
120
120
message += f": { detail } "
121
121
122
122
super ().__init__ (message )
123
123
124
124
125
- class PilotNotFoundError (GenericError ):
126
- head = "Pilot"
127
- tail = "not found"
125
+ class PilotNotFoundError (DiracFormattedError ):
126
+ pattern = "Pilot %s not found"
128
127
129
128
def __init__ (
130
129
self ,
131
130
data : dict [str , str ],
132
- detail : str | None = None ,
131
+ detail : str = "" ,
133
132
non_existing_pilots : set = set (),
134
133
):
135
134
super ().__init__ (data , detail )
136
135
self .non_existing_pilots = non_existing_pilots
137
136
138
137
139
- class PilotAlreadyExistsError (GenericError ):
140
- head = "Pilot"
141
- tail = "already exists"
138
+ class PilotAlreadyExistsError (DiracFormattedError ):
139
+ pattern = "Pilot %s already exists"
142
140
143
141
144
- class BadPilotCredentialsError (GenericError ):
145
- head = "Bad secret/pilot_stamp"
146
- tail = ""
142
+ class BadPilotCredentialsError (DiracFormattedError ):
143
+ pattern = "Bad secret/pilot_stamp %s "
147
144
148
145
149
- class BadPilotVOError (GenericError ):
150
- head = "Bad VO"
151
- tail = ""
146
+ class BadPilotVOError (DiracFormattedError ):
147
+ pattern = "Bad VO %s "
152
148
153
149
154
- class SecretNotFoundError (GenericError ):
155
- head = "Secret"
156
- tail = "not found"
150
+ class SecretNotFoundError (DiracFormattedError ):
151
+ pattern = "Secret %s not found"
157
152
158
153
159
- class CredentialsNotFoundError (GenericError ):
160
- head = "Credentials"
161
- tail = "not found"
154
+ class CredentialsNotFoundError (DiracFormattedError ):
155
+ pattern = "Credentials %s not found"
162
156
163
157
164
- class CredentialsAlreadyExistError (GenericError ):
165
- head = "Credentials"
166
- tail = "already exist"
158
+ class CredentialsAlreadyExistError (DiracFormattedError ):
159
+ pattern = "Credentials %s already exist"
167
160
168
161
169
- class SecretHasExpiredError (GenericError ):
170
- head = "Secret"
171
- tail = "has expired"
162
+ class SecretHasExpiredError (DiracFormattedError ):
163
+ pattern = "Secret %s has expired"
172
164
173
165
174
- class SecretAlreadyExistsError (GenericError ):
175
- head = "Secret"
176
- tail = "already exists"
166
+ class SecretAlreadyExistsError (DiracFormattedError ):
167
+ pattern = "Secret %s already exists"
177
168
178
169
179
- class PilotJobsNotFoundError (GenericError ):
180
- head = "Pilots or Jobs"
181
- tail = "not found"
170
+ class PilotJobsNotFoundError (DiracFormattedError ):
171
+ pattern = "Pilots or Jobs %s not found"
182
172
183
173
184
- class PilotAlreadyAssociatedWithJobError (GenericError ):
185
- head = "Pilot is already associated with a job"
186
- tail = ""
174
+ class PilotAlreadyAssociatedWithJobError (DiracFormattedError ):
175
+ pattern = "Pilot is already associated with a job %s "
0 commit comments