-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathexceptions.py
60 lines (42 loc) · 2.02 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
class GitLabWatchmanError(Exception):
""" Base class for exceptions in GitLab Watchman.
"""
class ElasticsearchMissingError(GitLabWatchmanError):
""" Exception raised when Elasticsearch is not enabled on the instance.
"""
def __init__(self, scope):
self.scope = scope
self.message = f'Elasticsearch is not configured, unable to use the search API for the scope: {self.scope}'
super().__init__(self.message)
class MissingEnvVarError(GitLabWatchmanError):
""" Exception raised when an environment variable is missing.
"""
def __init__(self, env_var):
self.env_var = env_var
self.message = f'Missing Environment Variable: {self.env_var}'
super().__init__(self.message)
class GitLabWatchmanAuthenticationError(GitLabWatchmanError):
""" Exception raised when unable to authenticate to GitLab.
"""
def __init__(self, error_message: str):
super().__init__('Unable to authenticate to GitLab: ' + error_message)
self.error_message = error_message
class GitLabWatchmanGetObjectError(GitLabWatchmanError):
""" Exception raised when an error occurs while getting a GitLab API object.
"""
def __init__(self, error_message: str, func, arg):
super().__init__(f'GitLab get object error: {error_message} - Function: {func.__name__} - Arg: {arg}')
self.error_message = error_message
class GitLabWatchmanNotAuthorisedError(GitLabWatchmanError):
""" Exception raised when the authenticated user is not authorized to access the
resource on the GitLab API.
"""
def __init__(self, error_message: str, func):
super().__init__(f'Not authorised: {error_message} - {func.__name__}')
self.error_message = error_message
class MisconfiguredConfFileError(Exception):
""" Exception raised when the config file watchman.conf is missing.
"""
def __init__(self):
self.message = f"The file watchman.conf doesn't contain config details for GitLab Watchman"
super().__init__(self.message)