/
exceptions.py
155 lines (96 loc) · 3.51 KB
/
exceptions.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
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
#!/usr/bin/env python
"""scriptworker exceptions."""
from scriptworker.constants import STATUSES
class ScriptWorkerException(Exception):
"""The base exception in scriptworker.
When raised inside of the run_loop loop, set the taskcluster task
status to at least ``self.exit_code``.
Attributes:
exit_code (int): this is set to 5 (internal-error).
"""
exit_code = STATUSES['internal-error']
class ScriptWorkerGPGException(ScriptWorkerException):
"""Scriptworker GPG error.
Attributes:
exit_code (int): this is set to 5 (internal-error).
"""
exit_code = STATUSES['internal-error']
class ScriptWorkerRetryException(ScriptWorkerException):
"""Scriptworker retry error.
Attributes:
exit_code (int): this is set to 4 (resource-unavailable)
"""
exit_code = STATUSES['resource-unavailable']
class ScriptWorkerTaskException(ScriptWorkerException):
"""Scriptworker task error.
To use::
import sys
try:
...
except ScriptWorkerTaskException as exc:
log.exception("log message")
sys.exit(exc.exit_code)
Attributes:
exit_code (int): this is 1 by default (failure)
"""
def __init__(self, *args, exit_code=1, **kwargs):
"""Initialize ScriptWorkerTaskException.
Args:
*args: These are passed on via super().
exit_code (int, optional): The exit_code we should exit with when
this exception is raised. Defaults to 1 (failure).
**kwargs: These are passed on via super().
"""
self.exit_code = exit_code
super(ScriptWorkerTaskException, self).__init__(*args, **kwargs)
class TaskVerificationError(ScriptWorkerTaskException):
"""Verification error on a Taskcluster task.
Use it when your script fails to validate any input from the task definition
"""
def __init__(self, msg):
"""Initialize TaskVerificationError.
Args:
msg (string): the error message
"""
super().__init__(msg, exit_code=STATUSES['malformed-payload'])
class BaseDownloadError(ScriptWorkerTaskException):
"""Base class for DownloadError and Download404.
Attributes:
exit_code (int): this is set to 4 (resource-unavailable).
"""
def __init__(self, msg):
"""Initialize Download404.
Args:
msg (string): the error message
"""
super(BaseDownloadError, self).__init__(
msg, exit_code=STATUSES['resource-unavailable']
)
class Download404(BaseDownloadError):
"""404 in ``scriptworker.utils.download_file``.
Attributes:
exit_code (int): this is set to 4 (resource-unavailable).
"""
class DownloadError(BaseDownloadError):
"""Failure in ``scriptworker.utils.download_file``.
Attributes:
exit_code (int): this is set to 4 (resource-unavailable).
"""
class CoTError(ScriptWorkerTaskException, KeyError):
"""Failure in Chain of Trust verification.
Attributes:
exit_code (int): this is set to 3 (malformed-payload).
"""
def __init__(self, msg):
"""Initialize CoTError.
Args:
msg (string): the error message
"""
super(CoTError, self).__init__(
msg, exit_code=STATUSES['malformed-payload']
)
class ConfigError(ScriptWorkerException):
"""Invalid configuration provided to scriptworker.
Attributes:
exit_code (int): this is set to 5 (internal-error).
"""