errors.py 1.55 KB
Newer Older
1
# Copyright (C) 2009-2010  Alexander Cherniuk <ts33kr@gmail.com>
2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

16 17
class BaseError(Exception):
    """
18 19 20
    Common base for errors which relate to a specific command.
    Encapsulates everything needed to identify a command, by either its
    object or name.
21 22 23
    """

    def __init__(self, message, command=None, name=None):
24 25
        self.message = message

26 27 28 29 30 31
        self.command = command
        self.name = name

        if command and not name:
            self.name = command.first_name

32
        super(BaseError, self).__init__()
33

34 35 36
    def __str__(self):
        return self.message

37 38
class DefinitionError(BaseError):
    """
Alexander Krotov's avatar
Alexander Krotov committed
39
    Used to indicate errors occurred on command definition.
40 41 42 43 44
    """
    pass

class CommandError(BaseError):
    """
Alexander Krotov's avatar
Alexander Krotov committed
45
    Used to indicate errors occurred during command execution.
46 47
    """
    pass
48 49 50 51 52 53

class NoCommandError(BaseError):
    """
    Used to indicate an inability to find the specified command.
    """
    pass