error.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. class OfflineImapError(Exception):
  2. """An Error during offlineimap synchronization"""
  3. class ERROR:
  4. """Severity level of an Exception
  5. * **MESSAGE**: Abort the current message, but continue with folder
  6. * **FOLDER_RETRY**: Error syncing folder, but do retry
  7. * **FOLDER**: Abort folder sync, but continue with next folder
  8. * **REPO**: Abort repository sync, continue with next account
  9. * **CRITICAL**: Immediately exit offlineimap
  10. """
  11. MESSAGE, FOLDER_RETRY, FOLDER, REPO, CRITICAL = 0, 10, 15, 20, 30
  12. def __init__(self, reason, severity, errcode=None):
  13. """
  14. :param reason: Human readable string suitable for logging
  15. :param severity: denoting which operations should be
  16. aborted. E.g. a ERROR.MESSAGE can occur on a faulty
  17. message, but a ERROR.REPO occurs when the server is
  18. offline.
  19. :param errcode: optional number denoting a predefined error
  20. situation (which let's us exit with a predefined exit
  21. value). So far, no errcodes have been defined yet.
  22. :type severity: OfflineImapError.ERROR value"""
  23. self.errcode = errcode
  24. self.severity = severity
  25. # 'reason' is stored in the Exception().args tuple.
  26. super(OfflineImapError, self).__init__(reason)
  27. @property
  28. def reason(self):
  29. return self.args[0]