exception.py 3.11 KB
Newer Older
Jakub Ružička's avatar
Jakub Ružička committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class ApkgException(Exception):
    msg_fmt = "An unknown error occurred"
    exit_code = 1

    def __init__(self, msg=None, exit_code=None, **kwargs):
        self.kwargs = kwargs
        if not msg:
            try:
                msg = self.msg_fmt % kwargs
            except Exception:
                # kwargs doesn't match those in message.
                # Returning this is still better than nothing.
                msg = self.msg_fmt
        if exit_code is not None:
            self.exit_code = exit_code
16
        super().__init__(msg)
Jakub Ružička's avatar
Jakub Ružička committed
17
18


Jakub Ružička's avatar
Jakub Ružička committed
19
20
21
22
23
24
25
26
class InvalidApkgCommand(ApkgException):
    msg_fmt = (
        "Invalid apkg command: %(command)s\n\n"
        "Run `apkg -h` to list supported commands."
    )
    exit_code = 10


27
28
29
30
31
class InvalidInput(ApkgException):
    msg_fmt = "Invalid input: %(fail)s"
    exit_code = 12


Jakub Ružička's avatar
Jakub Ružička committed
32
33
34
35
36
37
38
39
40
41
42
43
class InvalidType(ApkgException):
    msg_fmt = "Invalid type: $(var) must be %(desired)s but is %(type)s"
    exit_code = 14


class InvalidChoice(ApkgException):
    msg_fmt = "Invalid choice: %(var)s must be one of: %(opts)s (is: %(val)s)"
    exit_code = 16


class InvalidFormat(ApkgException):
    msg_fmt = "Invalid format: %(fmt)s"
Jakub Ružička's avatar
Jakub Ružička committed
44
45
46
47
48
    exit_code = 17


class InvalidArchiveFormat(InvalidFormat):
    msg_fmt = "Invalid archive format: %(fmt)s"
Jakub Ružička's avatar
Jakub Ružička committed
49
50
51
    exit_code = 18


52
53
54
55
56
class InvalidSourcePackageFormat(InvalidFormat):
    msg_fmt = "Invalid source package format: %(fmt)s"
    exit_code = 19


57
58
59
60
61
class MissingRequiredArgument(ApkgException):
    msg_fmt = "Missing required argument: %(arg)s"
    exit_code = 20


62
63
64
65
66
class MissingRequiredConfigOption(ApkgException):
    msg_fmt = "Missing required config option: %(opt)s"
    exit_code = 22


67
68
69
70
71
class MissingPackagingTemplate(ApkgException):
    msg_fmt = "Missing package template: %(temp)s"
    exit_code = 24


72
73
74
75
76
77
78
79
80
81
class ParsingFailed(ApkgException):
    msg_fmt = "Unable to parse: %(fail)s"
    exit_code = 30


class InvalidVersion(ApkgException):
    msg_fmt = "Invalid version: %(ver)s"
    exit_code = 40


82
83
84
85
86
class DistroNotSupported(ApkgException):
    msg_fmt = "Distro not supported: %(distro)s"
    exit_code = 44


87
class FileDownloadFailed(ApkgException):
88
    msg_fmt = "Failed to download file with code %(code)s:\n\n%(url)s"
89
90
91
    exit_code = 56


Jakub Ružička's avatar
Jakub Ružička committed
92
93
94
95
96
97
98
99
class CommandNotFound(ApkgException):
    msg_fmt = "Command not found: %(cmd)s"
    exit_code = 60


class CommandFailed(ApkgException):
    msg_fmt = "Command failed: %(cmd)s"
    exit_code = 62
100
101
102
103
104


class UnexpectedCommandOutput(ApkgException):
    msg_fmt = "Unexpected command output: %(out)s"
    exit_code = 66
105
106
107
108
109


class ArchiveNotFound(ApkgException):
    msg_fmt = "%(type)s archive not found: %(ar)s"
    exit_code = 80
110
111
112
113
114


class SourcePackageNotFound(ApkgException):
    msg_fmt = "%(type)s source package not found: %(srcpkg)s"
    exit_code = 82
115
116
117
118
119
120
121
122
123
124
125


class UnableToDetectUpstreamVersion(ApkgException):
    msg_fmt = (
        "Unable to detect upstream version.\n\n"
        "Please consider one of following:\n\n"
        "1) set upstream.archive_url "
        "(requires htmllistparse module)\n"
        "2) set upstream.version_script to custom script\n"
        "3) manually supply version using -v/--version option")
    exit_code = 90