exceptions.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. class TimesearchException(Exception):
  2. '''
  3. Base type for all of the Timesearch exceptions.
  4. Subtypes should have a class attribute `error_message`. The error message
  5. may contain {format} strings which will be formatted using the
  6. Exception's constructor arguments.
  7. '''
  8. error_message = ''
  9. def __init__(self, *args, **kwargs):
  10. self.given_args = args
  11. self.given_kwargs = kwargs
  12. self.error_message = self.error_message.format(*args, **kwargs)
  13. self.args = (self.error_message, args, kwargs)
  14. def __str__(self):
  15. return self.error_message
  16. OUTOFDATE = '''
  17. Database is out of date. {current} should be {new}.
  18. Please run utilities\\database_upgrader.py "{filepath.absolute_path}"
  19. '''.strip()
  20. class DatabaseOutOfDate(TimesearchException):
  21. '''
  22. Raised by TSDB __init__ if the user's database is behind.
  23. '''
  24. error_message = OUTOFDATE
  25. class DatabaseNotFound(TimesearchException, FileNotFoundError):
  26. error_message = 'Database file not found: "{}"'
  27. class NotExclusive(TimesearchException):
  28. '''
  29. For when two or more mutually exclusive actions have been requested.
  30. '''
  31. error_message = 'One and only one of {} must be passed.'