File: exceptions.py

package info (click to toggle)
python-softlayer 6.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,100 kB
  • sloc: python: 53,771; makefile: 289; sh: 57
file content (38 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download
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
"""
    SoftLayer.CLI.exceptions
    ~~~~~~~~~~~~~~~~~~~~~~~~
    Exceptions to be used in the CLI modules.

    :license: MIT, see LICENSE for more details.
"""


# pylint: disable=keyword-arg-before-vararg
class CLIHalt(SystemExit):
    """Smoothly halt the execution of the command. No error."""

    def __init__(self, code=0, *args):
        super().__init__(*args)
        self.code = code

    def __str__(self):
        return "<CLIHalt code=%s msg=%s>" % (self.code,
                                             getattr(self, 'message'))

    __repr__ = __str__


class CLIAbort(CLIHalt):
    """Halt the execution of the command. Gives an exit code of 2."""

    def __init__(self, msg, *args):
        super().__init__(code=2, *args)
        self.message = msg


class ArgumentError(CLIAbort):
    """Halt the execution of the command because of invalid arguments."""

    def __init__(self, msg, *args):
        super().__init__(msg, *args)
        self.message = "Argument Error: %s" % msg