2020-11-16 05:07:05 +00:00
|
|
|
from voussoirkit import stringtools
|
2017-03-05 05:56:23 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class ErrorTypeAdder(type):
|
|
|
|
'''
|
2017-11-17 00:46:39 +00:00
|
|
|
During definition, the Exception class will automatically receive a class
|
|
|
|
attribute called `error_type` which is just the class's name as a string
|
|
|
|
in the loudsnake casing style. NoSuchPhoto -> NO_SUCH_PHOTO.
|
|
|
|
|
|
|
|
This is used for serialization of the exception object and should
|
|
|
|
basically act as a status code when displaying the error to the user.
|
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
Thanks Unutbu
|
|
|
|
http://stackoverflow.com/a/18126678
|
|
|
|
'''
|
|
|
|
def __init__(cls, name, bases, clsdict):
|
|
|
|
type.__init__(cls, name, bases, clsdict)
|
2020-11-16 05:07:05 +00:00
|
|
|
cls.error_type = stringtools.pascal_to_loudsnakes(name)
|
2017-03-05 05:56:23 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class EtiquetteException(Exception, metaclass=ErrorTypeAdder):
|
2017-11-17 00:46:39 +00:00
|
|
|
'''
|
|
|
|
Base type for all of the Etiquette exceptions.
|
|
|
|
Subtypes should have a class attribute `error_message`. The error message
|
|
|
|
may contain {format} strings which will be formatted using the
|
|
|
|
Exception's constructor arguments.
|
|
|
|
'''
|
2017-03-17 09:30:02 +00:00
|
|
|
error_message = ''
|
2018-03-11 09:54:59 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2018-02-17 05:28:36 +00:00
|
|
|
super().__init__()
|
2017-03-05 06:27:24 +00:00
|
|
|
self.given_args = args
|
|
|
|
self.given_kwargs = kwargs
|
2017-03-05 05:56:23 +00:00
|
|
|
self.error_message = self.error_message.format(*args, **kwargs)
|
2017-04-23 04:20:03 +00:00
|
|
|
self.args = (self.error_message, args, kwargs)
|
2017-03-17 09:30:02 +00:00
|
|
|
|
2017-11-17 00:31:10 +00:00
|
|
|
def __str__(self):
|
2021-04-01 02:35:38 +00:00
|
|
|
return f'{self.error_type}: {self.error_message}'
|
2017-11-17 00:31:10 +00:00
|
|
|
|
2021-01-01 20:56:05 +00:00
|
|
|
def jsonify(self):
|
|
|
|
j = {
|
|
|
|
'type': 'error',
|
|
|
|
'error_type': self.error_type,
|
|
|
|
'error_message': self.error_message,
|
|
|
|
}
|
|
|
|
return j
|
|
|
|
|
2020-09-19 10:13:23 +00:00
|
|
|
# NO SUCH ##########################################################################################
|
2017-02-26 09:04:07 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class NoSuch(EtiquetteException):
|
2016-12-13 03:49:36 +00:00
|
|
|
pass
|
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchAlbum(NoSuch):
|
|
|
|
error_message = 'Album "{}" does not exist.'
|
2017-02-05 02:30:02 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchBookmark(NoSuch):
|
|
|
|
error_message = 'Bookmark "{}" does not exist.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchGroup(NoSuch):
|
|
|
|
error_message = 'Group "{}" does not exist.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchPhoto(NoSuch):
|
|
|
|
error_message = 'Photo "{}" does not exist.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchSynonym(NoSuch):
|
|
|
|
error_message = 'Synonym "{}" does not exist.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchTag(NoSuch):
|
|
|
|
error_message = 'Tag "{}" does not exist.'
|
|
|
|
|
|
|
|
class NoSuchUser(NoSuch):
|
|
|
|
error_message = 'User "{}" does not exist.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2020-09-19 10:13:23 +00:00
|
|
|
# EXISTS ###########################################################################################
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class Exists(EtiquetteException):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class AlbumExists(Exists):
|
2017-03-17 06:57:31 +00:00
|
|
|
error_message = 'Album "{}" already exists.'
|
2018-03-11 09:54:59 +00:00
|
|
|
|
2017-03-17 06:57:31 +00:00
|
|
|
def __init__(self, album):
|
|
|
|
self.album = album
|
2017-04-23 04:20:03 +00:00
|
|
|
EtiquetteException.__init__(self, album)
|
2017-03-17 06:57:31 +00:00
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class GroupExists(Exists):
|
2020-02-19 21:11:57 +00:00
|
|
|
error_message = '{member} already in group {group}.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class PhotoExists(Exists):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Photo "{}" already exists.'
|
2018-03-11 09:54:59 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
def __init__(self, photo):
|
|
|
|
self.photo = photo
|
2017-04-23 04:20:03 +00:00
|
|
|
EtiquetteException.__init__(self, photo)
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class TagExists(Exists):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Tag "{}" already exists.'
|
2018-03-11 09:54:59 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
def __init__(self, tag):
|
|
|
|
self.tag = tag
|
2017-04-23 04:20:03 +00:00
|
|
|
EtiquetteException.__init__(self, tag)
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class UserExists(Exists):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'User "{}" already exists.'
|
2018-03-11 09:54:59 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
def __init__(self, user):
|
|
|
|
self.user = user
|
2017-04-23 04:20:03 +00:00
|
|
|
EtiquetteException.__init__(self, user)
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2020-09-19 10:13:23 +00:00
|
|
|
# TAG ERRORS #######################################################################################
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2018-09-23 06:10:18 +00:00
|
|
|
class CantGroupSelf(EtiquetteException):
|
|
|
|
error_message = 'Cannot group {} into itself.'
|
|
|
|
|
2017-02-26 09:04:07 +00:00
|
|
|
class CantSynonymSelf(EtiquetteException):
|
2018-09-23 21:57:25 +00:00
|
|
|
error_message = 'Cannot make {} a synonym of itself.'
|
2016-12-21 05:33:14 +00:00
|
|
|
|
2017-03-05 06:27:24 +00:00
|
|
|
class EasyBakeError(EtiquetteException):
|
2017-03-17 09:30:02 +00:00
|
|
|
error_message = '{}'
|
2017-03-05 06:27:24 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class RecursiveGrouping(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = '{group} is an ancestor of {member}.'
|
2016-12-21 02:31:09 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class TagTooLong(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Tag "{}" is too long.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class TagTooShort(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Tag "{}" has too few valid characters.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2020-09-19 10:13:23 +00:00
|
|
|
# USER ERRORS ######################################################################################
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2017-03-17 08:08:51 +00:00
|
|
|
class AlreadySignedIn(EtiquetteException):
|
|
|
|
error_message = 'You\'re already signed in.'
|
|
|
|
|
2021-01-09 23:45:06 +00:00
|
|
|
class CantDeleteUser(EtiquetteException):
|
|
|
|
error_message = '{} can\'t be deleted because they still have possessions.'
|
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class InvalidPassword(EtiquetteException):
|
|
|
|
error_message = 'Password is invalid.'
|
|
|
|
|
|
|
|
class InvalidUsername(EtiquetteException):
|
|
|
|
error_message = 'Username "{username}" is invalid.'
|
|
|
|
|
|
|
|
class InvalidUsernameChars(InvalidUsername):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Username "{username}" contains invalid characters: {badchars}.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class PasswordTooShort(InvalidPassword):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Password is shorter than the minimum of {min_length}.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class UsernameTooLong(InvalidUsername):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Username "{username}" is longer than maximum of {max_length}.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2018-02-17 06:13:54 +00:00
|
|
|
class UsernameTooShort(InvalidUsername):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Username "{username}" is shorter than minimum of {min_length}.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2018-04-15 21:23:24 +00:00
|
|
|
class DisplayNameTooLong(EtiquetteException):
|
|
|
|
error_message = 'Display name "{display_name}" is longer than maximum of {max_length}.'
|
|
|
|
|
2021-01-09 23:42:51 +00:00
|
|
|
class Unauthorized(EtiquetteException):
|
|
|
|
error_message = 'You\'re not allowed to do that.'
|
|
|
|
|
2017-02-26 09:04:07 +00:00
|
|
|
class WrongLogin(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Wrong username-password combination.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2020-09-19 10:13:23 +00:00
|
|
|
# SQL ERRORS #######################################################################################
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2020-02-05 02:15:14 +00:00
|
|
|
class BadSQL(EtiquetteException):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class BadTable(BadSQL):
|
|
|
|
error_message = 'Table "{}" does not exist.'
|
|
|
|
|
2020-09-19 10:13:23 +00:00
|
|
|
# GENERAL ERRORS ###################################################################################
|
2020-02-05 02:15:14 +00:00
|
|
|
|
2018-03-13 09:21:35 +00:00
|
|
|
class BadDataDirectory(EtiquetteException):
|
|
|
|
'''
|
|
|
|
Raised by PhotoDB __init__ if the requested data_directory is invalid.
|
|
|
|
'''
|
|
|
|
error_message = 'Bad data directory "{}"'
|
|
|
|
|
2017-11-17 00:33:40 +00:00
|
|
|
OUTOFDATE = '''
|
2018-11-25 06:06:16 +00:00
|
|
|
Database is out of date. {existing} should be {new}.
|
2021-01-04 10:38:26 +00:00
|
|
|
Please run utilities\\database_upgrader.py "{filepath.absolute_path}"
|
2017-11-17 00:33:40 +00:00
|
|
|
'''.strip()
|
|
|
|
class DatabaseOutOfDate(EtiquetteException):
|
|
|
|
'''
|
|
|
|
Raised by PhotoDB __init__ if the user's database is behind.
|
|
|
|
'''
|
|
|
|
error_message = OUTOFDATE
|
|
|
|
|
2020-09-20 18:31:51 +00:00
|
|
|
class DeletedObject(EtiquetteException):
|
|
|
|
'''
|
|
|
|
For when thing.deleted == True.
|
|
|
|
'''
|
|
|
|
error_message = '{} has already been deleted by another caller.'
|
|
|
|
|
2017-03-17 02:54:12 +00:00
|
|
|
class FeatureDisabled(EtiquetteException):
|
|
|
|
'''
|
|
|
|
For when features of the system have been disabled by the configuration.
|
|
|
|
'''
|
2020-01-30 07:52:25 +00:00
|
|
|
error_message = 'This feature has been disabled. Requires {}.'
|
2017-03-17 02:54:12 +00:00
|
|
|
|
2021-01-09 23:41:52 +00:00
|
|
|
class NoClosestPhotoDB(EtiquetteException):
|
|
|
|
'''
|
|
|
|
For calls to PhotoDB.closest_photodb where none exists between cwd and
|
|
|
|
drive root.
|
|
|
|
'''
|
2021-05-16 23:58:53 +00:00
|
|
|
error_message = 'There is no PhotoDB in "{}" or its parents.'
|
2021-01-09 23:41:52 +00:00
|
|
|
|
2020-09-28 06:38:49 +00:00
|
|
|
class NoYields(EtiquetteException):
|
|
|
|
'''
|
|
|
|
For when all of the yield_* arguments have been provided as False, and thus
|
|
|
|
there is nothing for the called function to yield.
|
|
|
|
'''
|
|
|
|
error_message = 'At least one of {} must be selected.'
|
|
|
|
|
2017-02-26 09:04:07 +00:00
|
|
|
class NotExclusive(EtiquetteException):
|
2016-12-13 03:49:36 +00:00
|
|
|
'''
|
|
|
|
For when two or more mutually exclusive actions have been requested.
|
|
|
|
'''
|
2017-04-21 01:29:30 +00:00
|
|
|
error_message = 'One and only one of {} must be passed.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class OutOfOrder(EtiquetteException):
|
2016-12-13 03:49:36 +00:00
|
|
|
'''
|
2017-02-26 09:04:07 +00:00
|
|
|
For when a requested minmax range (a, b) has b > a
|
2016-12-13 03:49:36 +00:00
|
|
|
'''
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Range "{range}": minimum "{min}" and maximum "{max}" are out of order.'
|