summaryrefslogtreecommitdiff
path: root/cmd2/exceptions.py
blob: c5a0820241d1d51872386d95306b97068f743244 (plain)
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
# coding=utf-8
"""Custom exceptions for cmd2"""


############################################################################################################
# The following exceptions are part of the public API
############################################################################################################


class SkipPostcommandHooks(Exception):
    """
    Custom exception class for when a command has a failure bad enough to skip post command
    hooks, but not bad enough to print the exception to the user.
    """

    pass


class Cmd2ArgparseError(SkipPostcommandHooks):
    """
    A ``SkipPostcommandHooks`` exception for when a command fails to parse its arguments.
    Normally argparse raises a SystemExit exception in these cases. To avoid stopping the command
    loop, catch the SystemExit and raise this instead. If you still need to run post command hooks
    after parsing fails, just return instead of raising an exception.
    """

    pass


class CommandSetRegistrationError(Exception):
    """
    Exception that can be thrown when an error occurs while a CommandSet is being added or removed
    from a cmd2 application.
    """

    pass


############################################################################################################
# The following exceptions are NOT part of the public API and are intended for internal use only.
############################################################################################################


class Cmd2ShlexError(Exception):
    """Raised when shlex fails to parse a command line string in StatementParser"""

    pass


class EmbeddedConsoleExit(SystemExit):
    """Custom exception class for use with the py command."""

    pass


class EmptyStatement(Exception):
    """Custom exception class for handling behavior when the user just presses <Enter>."""

    pass


class RedirectionError(Exception):
    """Custom exception class for when redirecting or piping output fails"""

    pass