Source

DailyPromptBot / minibot / errors.py

Full commit
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# The Daily Prompt Mini-Bot - A Shut Up and Write Project
# Author: Marc-Alexandre Chan <laogeodritt at arenthil.net>
#-------------------------------------------------------------------------------
#
# Copyright (c) 2012 Marc-Alexandre Chan. Licensed under the GNU GPL version 3
#
# 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/>.
#
#-------------------------------------------------------------------------------

# GENERAL
class MinibotError(StandardError):
    """ Abstract base class for DailyPromptMinibot errors. """
    pass

class InvalidRedditError(RuntimeError, MinibotError):
    """ Raised when specified reddit cannot be found. """
    pass

class ConfigFileError(MinibotError):
    """ Raised when a config file cannot be found or read. """
    pass

class LogFileError(MinibotError):
    """ Raised when a log file cannot be accessed. """
    pass

# EVENT SCHEDULER
class ResourceError(MinibotError):
    """ Raised when an Event requires a resource not known to the Event
    Scheduler. """
    pass

class AttachedEventError(MinibotError):
    """ Raised when an Event has already been assigned an owner attribute upon
    queueing. These Event objects are unsafe to queue into the scheduler, as
    they have been queued previously and may have already run; hence, the
    internal state of the Event cannot be guaranteed. """
    pass

class EventNotFoundError(MinibotError):
    """ Raised when an Event is specified to remove or manipulate, but it is
    not in the Scheduler's queue. Argument is the event itself. """
    pass

class SchedulerStoppedError(MinibotError):
    """ Raised if an event is queued while the scheduler is in shutdown mode
    (``request_exit()`` was called). """
    pass

# EVENTS
class CommandError(MinibotError):
    """ Abstract base class for Command errors. """

class CommandParseError(ValueError, CommandError):
    """ Raised when an error occurs while parsing a command message. """
    pass

class CommandNameError(ValueError, CommandError):
    """ Raised when a command message specifies a command which is invalid. """
    pass

class CommandParameterError(ValueError, CommandError):
    """ Raised when a command message does not contain valid parameters. """
    pass

class BadCommandError(ValueError, CommandError):
    """ Raised when a command message is invalid and no parsing can be done. """
    pass

class MissingParameterError(KeyError, CommandError):
    """ Raised when a required command parameter is not passed in a command
    message. """
    pass

# CONFIG
class ConfigValueError(ValueError):
    """ Raised when an invalid configuration value is set or loaded from a file.
    """

class ConfigNameError(ValueError):
    """ Raised when an invalid configuration field is set.
    """

# REDDIT
from praw.errors import *
from urllib2 import HTTPError, URLError

# SQL
from sqlalchemy.exc import SQLAlchemyError, DBAPIError