-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
exceptions.py
92 lines (72 loc) · 3.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
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
import errno
import os
import sys
class RequirementError(Exception):
pass
class MissingParameter(Exception):
def __init__(self, param):
self.message = self.get_message(param)
super().__init__(self.message)
@classmethod
def get_message(cls, param):
return f"Missing Parameter: {param}"
def show(self, param):
print(self.message, file=sys.stderr, flush=True)
class FileCorruptException(OSError):
def __init__(self, path, *args, **kwargs):
backup_path = kwargs.pop("backup_path", None)
if not backup_path and args:
args = reversed(args)
backup_path = args.pop()
if not isinstance(backup_path, str) or not os.path.exists(
os.path.abspath(os.path.dirname(backup_path))
):
args.append(backup_path)
backup_path = None
if args:
args = reversed(args)
self.message = self.get_message(path, backup_path=backup_path)
super().__init__(self.message)
def get_message(self, path, backup_path=None):
message = f"ERROR: Failed to load file at {path}"
if backup_path:
msg = f"it will be backed up to {backup_path} and removed"
else:
msg = "it will be removed and replaced on the next lock."
message = f"{message}\nYour lockfile is corrupt, {msg}"
return message
def show(self):
print(self.message, file=sys.stderr, flush=True)
class LockfileCorruptException(FileCorruptException):
def __init__(self, path, backup_path=None):
self.message = self.get_message(path, backup_path=backup_path)
super().__init__(self.message)
def get_message(self, path, backup_path=None):
message = f"ERROR: Failed to load lockfile at {path}"
if backup_path:
msg = f"it will be backed up to {backup_path} and removed"
else:
msg = "it will be removed and replaced on the next lock."
message = f"{message}\nYour lockfile is corrupt, {msg}"
return message
def show(self, path, backup_path=None):
print(self.message, file=sys.stderr, flush=True)
class PipfileCorruptException(FileCorruptException):
def __init__(self, path, backup_path=None):
self.message = self.get_message(path, backup_path=backup_path)
super().__init__(self.message)
def get_message(self, path, backup_path=None):
message = f"ERROR: Failed to load Pipfile at {path}"
if backup_path:
msg = f"it will be backed up to {backup_path} and removed"
else:
msg = "it will be removed and replaced on the next lock."
message = f"{message}\nYour Pipfile is corrupt, {msg}"
return message
def show(self, path, backup_path=None):
print(self.message, file=sys.stderr, flush=True)
class PipfileNotFound(FileNotFoundError):
def __init__(self, path, *args, **kwargs):
self.errno = errno.ENOENT
self.filename = path
super().__init__(self.filename)