-
Notifications
You must be signed in to change notification settings - Fork 18
/
exceptions.py
110 lines (76 loc) · 2.77 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
from argparse import ArgumentParser
from typing import Optional
class TaskipyError(Exception):
exit_code = 1
class InvalidRunnerTypeError(TaskipyError):
def __str__(self):
return (
'invalid value: runner is not a string. '
'please check [tool.taskipy.settings.runner]'
)
class MissingPyProjectFileError(TaskipyError):
def __str__(self):
return 'no pyproject.toml file found in this directory or parent directories'
class MalformedPyProjectError(TaskipyError):
def __init__(self, reason: Optional[str] = None):
super().__init__()
self.reason = reason
def __str__(self):
message = 'pyproject.toml file is malformed and could not be read'
if self.reason:
message += f'. reason: {self.reason}'
return message
class TaskNotFoundError(TaskipyError):
exit_code = 127
def __init__(self, task_name: str):
super().__init__()
self.task = task_name
def __str__(self):
return f'could not find task "{self.task}"'
class MalformedTaskError(TaskipyError):
def __init__(self, task_name: str, reason: str):
super().__init__()
self.task = task_name
self.reason = reason
def __str__(self):
return f'the task "{self.task}" in the pyproject.toml file is malformed. reason: {self.reason}'
class InvalidUsageError(TaskipyError):
exit_code = 127
def __init__(self, parser: ArgumentParser):
super().__init__()
self.__parser = parser
def __str__(self):
return self.__parser.format_usage().strip('\n')
class MissingTaskipySettingsSectionError(TaskipyError):
exit_code = 127
def __str__(self):
return (
'no settings found. add a [tools.taskipy.settings]'
'section to your pyproject.toml'
)
class MissingTaskipyTasksSectionError(TaskipyError):
exit_code = 127
def __str__(self):
return (
'no tasks found. add a [tool.taskipy.tasks] '
'section to your pyproject.toml'
)
class EmptyTasksSectionError(TaskipyError):
exit_code = 127
def __str__(self):
return (
'no tasks found. create your first task '
'by adding it to your pyproject.toml file under [tool.taskipy.tasks]'
)
class CircularVariableError(TaskipyError):
exit_code = 127
def __str__(self):
return 'cannot resolve variables, found variables that depend on each other.'
class InvalidVariableError(TaskipyError):
exit_code = 127
def __init__(self, variable: str, reason: str) -> None:
super().__init__()
self.variable = variable
self.reason = reason
def __str__(self):
return f'variable {self.variable} is invalid. reason: {self.reason}'