-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexceptions.py
More file actions
609 lines (417 loc) · 15.5 KB
/
exceptions.py
File metadata and controls
609 lines (417 loc) · 15.5 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
# Copyright 2016-2018 Scality
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Literal
from bert_e.lib.template_loader import render
# When dont_repeat_if_in_history is None, Bert-E will look for the message
# in the whole list of comments.
NEVER_REPEAT = None
class BertE_Exception(Exception):
code = -1
status: Literal[None, "in_progress", "queued", "success", "failure"] = None
# base exceptions
class TemplateException(BertE_Exception):
code = -2
template = None
# whether to re-publish if the message is already in the history
dont_repeat_if_in_history = -1
def __init__(self, **kwargs):
self.kwargs = kwargs
assert 'active_options' in kwargs
assert self.code != 0
assert self.template
norepeat = self.dont_repeat_if_in_history
assert norepeat is None or norepeat >= -1
self.msg = render(self.template, code=self.code, **kwargs)
super(TemplateException, self).__init__(self.msg)
@property
def title(self) -> str:
# Return the exception class name as the title
return self.__class__.__name__
class InternalException(BertE_Exception):
code = 1
class SilentException(BertE_Exception):
code = 2
# template for informative exceptions
class InformationException(TemplateException):
dont_repeat_if_in_history = NEVER_REPEAT
# template exceptions
class InitMessage(InformationException):
code = 100
template = 'init.md'
class HelpMessage(TemplateException):
code = 101
template = 'help.md'
dont_repeat_if_in_history = 0 # allow repeating if requested by user
class SuccessMessage(TemplateException):
code = 102
template = 'successful_merge.md'
status = "success"
class CommandNotImplemented(TemplateException):
code = 103
template = 'not_implemented.md'
dont_repeat_if_in_history = 0 # allow repeating if requested by user
class StatusReport(TemplateException):
code = 104
template = 'status.md'
dont_repeat_if_in_history = 0 # allow repeating if requested by user
class IncompatibleSourceBranchPrefix(TemplateException):
code = 106
template = 'incompatible_source_branch_prefix.md'
status = "failure"
class MissingJiraId(TemplateException):
code = 107
template = 'missing_jira_id.md'
status = "failure"
class JiraIssueNotFound(TemplateException):
code = 108
template = 'jira_issue_not_found.md'
status = "failure"
class IssueTypeNotSupported(TemplateException):
code = 109
template = 'issue_type_not_supported.md'
status = "failure"
class IncorrectJiraProject(TemplateException):
code = 110
template = 'incorrect_jira_project.md'
status = "failure"
class MismatchPrefixIssueType(TemplateException):
code = 111
template = 'mismatch_prefix_issue_type.md'
status = "failure"
class IncorrectFixVersion(TemplateException):
code = 112
template = 'incorrect_fix_version.md'
status = "failure"
class BranchHistoryMismatch(TemplateException):
code = 113
template = 'history_mismatch.md'
status = "failure"
class Conflict(TemplateException):
code = 114
template = 'conflict.md'
status = "failure"
class ApprovalRequired(TemplateException):
code = 115
template = 'need_approval.md'
status = "queued"
class BuildFailed(TemplateException):
code = 118
template = 'build_failed.md'
status = "failure"
class AfterPullRequest(TemplateException):
code = 120
template = 'after_pull_request.md'
status = "queued"
class IntegrationDataCreated(InformationException):
code = 121
template = 'integration_data_created.md'
class UnknownCommand(TemplateException):
code = 122
template = 'unknown_command.md'
status = "failure"
class NotEnoughCredentials(TemplateException):
code = 123
template = "not_enough_credentials.md"
status = "failure"
class QueueConflict(TemplateException):
code = 124
template = "queue_conflict.md"
status = "failure"
class Queued(TemplateException):
code = 125
template = 'queued.md'
status = "in_progress"
def __init__(self, branches, ignored, issue, author, active_options):
"""Save args for later use by tests."""
self.branches = branches
self.ignored = ignored
self.issue = issue
self.author = author
self.active_options = active_options
super(Queued, self).__init__(
branches=branches,
ignored=ignored,
issue=issue,
author=author,
active_options=active_options
)
class PartialMerge(TemplateException):
code = 126
template = 'partial_merge.md'
dont_repeat_if_in_history = 0 # allow repeating as many times as it occurs
status = "success"
class QueueOutOfOrder(TemplateException):
code = 127
template = "queue_out_of_order.md"
status = "failure"
class ResetComplete(TemplateException):
code = 128
template = "reset_complete.md"
class LossyResetWarning(TemplateException):
code = 129
template = "lossy_reset.md"
status = "failure"
class IncorrectCommandSyntax(TemplateException):
code = 130
template = "incorrect_command_syntax.md"
status = "failure"
class IncorrectPullRequestNumber(TemplateException):
code = 131
template = "incorrect_pull_request_number.md"
status = "failure"
class SourceBranchTooOld(TemplateException):
code = 132
template = "source_branch_too_old.md"
status = "failure"
class FlakyGitHost(TemplateException):
code = 133
template = "flaky_git_host.md"
status = "failure"
class NotAuthor(TemplateException):
code = 134
template = "not_author.md"
status = "failure"
class RequestIntegrationBranches(TemplateException):
code = 135
template = "request_integration_branches.md"
# TODO: review if it should be failure.
status = "queued"
class QueueBuildFailedMessage(TemplateException):
code = 136
template = "queue_build_failed.md"
# internal exceptions
class UnableToSendEmail(InternalException):
code = 201
class ImproperEmailFormat(InternalException):
code = 202
class BranchNameInvalid(InternalException):
code = 203
def __init__(self, name):
msg = 'Invalid name: %r' % name
super(BranchNameInvalid, self).__init__(msg)
class ReleaseAlreadyExists(InternalException):
code = 204
def __init__(self, branch, tag):
msg = 'Branch %r must be deleted as %r has been created, ' \
'you must use a hotfix branch if you really intend ' \
'to target this version.' \
% (branch, tag)
super(ReleaseAlreadyExists, self).__init__(msg)
class UnrecognizedBranchPattern(InternalException):
code = 207
class JiraUnknownIssueType(InternalException):
code = 209
def __init__(self, issue_type):
msg = ("Jira issue: unknown type %r" % issue_type)
super(JiraUnknownIssueType, self).__init__(msg)
class DevBranchesNotSelfContained(InternalException):
code = 210
def __init__(self, upstream_branch, downstream_branch):
msg = ("The git repository appears to be in a bad shape. "
"Branch `%s` is not included in branch `%s`." % (
upstream_branch, downstream_branch))
super(DevBranchesNotSelfContained, self).__init__(msg)
class DevBranchDoesNotExist(InternalException):
code = 211
def __init__(self, branch):
msg = ("The git repository appears to be in a bad shape. "
"Branch `%s` does not exist." % branch)
super(DevBranchDoesNotExist, self).__init__(msg)
class NotASingleDevBranch(InternalException):
code = 212
def __init__(self):
msg = ("The git repository appears to be in a bad shape. "
"There is not a single development to merge to.")
super(NotASingleDevBranch, self).__init__(msg)
class PullRequestSkewDetected(InternalException):
code = 213
def __init__(self, pr_id, local_sha1, pr_sha1):
msg = "The pull request %d contains a more recent commit " \
"than I expected (expected %s, got %s)" \
% (pr_id, local_sha1, pr_sha1)
super(PullRequestSkewDetected, self).__init__(msg)
class IncoherentQueues(InternalException):
code = 214
def __init__(self, errors):
"""Display errors as a list, with error code included
for easy parsing in tests and easy lookup in code.
"""
msg = 'The queues are in an incoherent state, ' \
'I will block until the following points are resolved:\n' + \
'\n'.join([" - [{code}] {label}".format(code=error.code,
label=error.msg)
for error in errors])
super(IncoherentQueues, self).__init__(msg)
class InvalidQueueBranch(InternalException):
code = 215
def __init__(self, branch):
msg = "This is not a queue branch:" \
"%s" % (branch)
super(InvalidQueueBranch, self).__init__(msg)
class QueuesNotValidated(InternalException):
code = 216
def __init__(self):
msg = "The queues have not been validated, can't use them."
super(QueuesNotValidated, self).__init__(msg)
class UnsupportedTokenType(InternalException):
code = 217
def __init__(self, token):
msg = "The input token %r is not supported." % token
super(UnsupportedTokenType, self).__init__(msg)
class SettingsFileNotFound(InternalException):
code = 218
def __init__(self, filename):
msg = "Cannot find the settings file at %r." % filename
super(SettingsFileNotFound, self).__init__(msg)
class IncorrectSettingsFile(InternalException):
code = 219
def __init__(self, filename):
msg = "Cannot parse the settings file at %r." % filename
super().__init__(msg)
class MalformedSettings(InternalException):
code = 220
def __init__(self, filename, errors, data):
msg = "One or more errors were found while parsing {!r}:\n{}".format(
filename, errors
)
super().__init__(msg)
class TaskAPIError(InternalException):
code = 221
def __init__(self, method, err):
msg = "There was an error while accessing the task " \
"API %r (%s)" % (method, err)
super(TaskAPIError, self).__init__(msg)
class WrongDestination(TemplateException):
code = 222
template = 'incorrect_destination.md'
class QueueValidationError(Exception):
"""Extend simple string class with an error code and recovery potential."""
code = 'Q000'
auto_recovery = False # set to True to let Bert-E fix the problem alone
def __init__(self, msg):
self.msg = msg
super(QueueValidationError, self).__init__(msg)
class MasterQueueMissing(QueueValidationError):
code = 'Q001'
auto_recovery = False
@staticmethod
def _format_version(version):
if not version:
return '[]'
if len(version) == 1 or (len(version) > 1 and version[1] is None):
return f"{version[0]}"
if len(version) == 2 or (len(version) > 2 and version[2] is None):
return f"{version[0]}.{version[1]}"
return f"{version[0]}.{version[1]}.{version[2]}"
def __init__(self, version):
version_str = self._format_version(version)
msg = "there are integration queues on " \
f"this version but q/{version_str} is missing"
super().__init__(msg)
class MasterQueueLateVsDev(QueueValidationError):
code = 'Q002'
auto_recovery = False
def __init__(self, masterq, dev):
msg = '{masterq} is late ' \
'compared to {dev}'.format(**locals())
super(MasterQueueLateVsDev, self).__init__(msg)
class MasterQueueNotInSync(QueueValidationError):
code = 'Q003'
auto_recovery = False
def __init__(self, masterq, dev):
msg = 'no pending integration ' \
'queues, yet {masterq} is not in sync ' \
'with {dev}'.format(**locals())
super(MasterQueueNotInSync, self).__init__(msg)
class MasterQueueLateVsInt(QueueValidationError):
code = 'Q004'
auto_recovery = False
def __init__(self, masterq, intq):
msg = '{masterq} is more recent ' \
'than greatest integration queue ' \
'{intq}'.format(**locals())
super(MasterQueueLateVsInt, self).__init__(msg)
class MasterQueueYoungerThanInt(QueueValidationError):
code = 'Q005'
auto_recovery = False
def __init__(self, masterq, intq):
msg = 'greatest integration queue {intq} ' \
'is late compared to {masterq}'.format(**locals())
super(MasterQueueYoungerThanInt, self).__init__(msg)
class MasterQueueDiverged(QueueValidationError):
code = 'Q006'
auto_recovery = False
def __init__(self, masterq, intq):
msg = '{masterq} and greatest ' \
'integration queue {intq} have ' \
'diverged'.format(**locals())
super(MasterQueueDiverged, self).__init__(msg)
class QueueInclusionIssue(QueueValidationError):
code = 'Q007'
auto_recovery = False
def __init__(self, nextq, intq):
msg = '{intq} is not included in ' \
'{nextq}'.format(**locals())
super(QueueInclusionIssue, self).__init__(msg)
class QueueInconsistentPullRequestsOrder(QueueValidationError):
code = 'Q008'
auto_recovery = False
def __init__(self):
msg = 'The order of integration queues with respect to ' \
'the pull requests appears to be incorrect'
super(QueueInconsistentPullRequestsOrder, self).__init__(msg)
class QueueIncomplete(QueueValidationError):
code = 'Q009'
auto_recovery = False
def __init__(self):
msg = 'An integration queue is missing'
super(QueueIncomplete, self).__init__(msg)
# silent exceptions
class CommentAlreadyExists(SilentException):
code = 300
class NotMyJob(SilentException):
code = 301
class NothingToDo(SilentException):
code = 302
class BuildInProgress(SilentException):
code = 303
status = "in_progress"
class BuildNotStarted(SilentException):
code = 304
class PullRequestDeclined(SilentException):
code = 305
class Merged(SilentException):
code = 306
class JobSuccess(SilentException):
code = 307
class JobFailure(SilentException):
code = 308
class QueueBuildFailed(SilentException):
code = 309
class BabysitRetry(TemplateException):
"""Raised when babysit mode triggers a retry of failed GitHub Actions."""
code = 140
template = 'babysit_retry.md'
dont_repeat_if_in_history = 0 # allow repeating for each retry
status = "in_progress"
class BabysitExhausted(TemplateException):
"""Raised when babysit mode has exhausted all retry attempts."""
code = 141
template = 'babysit_exhausted.md'
status = "failure"
class BabysitCancelled(TemplateException):
"""Raised when babysit mode is cancelled due to new commits."""
code = 142
template = 'babysit_cancelled.md'
status = "in_progress"