exc.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
  2. #
  3. # This module is part of GitDB and is released under
  4. # the New BSD License: https://opensource.org/license/bsd-3-clause/
  5. """Module with common exceptions"""
  6. from gitdb.util import to_hex_sha
  7. __all__ = [
  8. 'AmbiguousObjectName',
  9. 'BadName',
  10. 'BadObject',
  11. 'BadObjectType',
  12. 'InvalidDBRoot',
  13. 'ODBError',
  14. 'ParseError',
  15. 'UnsupportedOperation',
  16. 'to_hex_sha',
  17. ]
  18. class ODBError(Exception):
  19. """All errors thrown by the object database"""
  20. class InvalidDBRoot(ODBError):
  21. """Thrown if an object database cannot be initialized at the given path"""
  22. class BadObject(ODBError):
  23. """The object with the given SHA does not exist. Instantiate with the
  24. failed sha"""
  25. def __str__(self):
  26. return "BadObject: %s" % to_hex_sha(self.args[0])
  27. class BadName(ODBError):
  28. """A name provided to rev_parse wasn't understood"""
  29. def __str__(self):
  30. return "Ref '%s' did not resolve to an object" % self.args[0]
  31. class ParseError(ODBError):
  32. """Thrown if the parsing of a file failed due to an invalid format"""
  33. class AmbiguousObjectName(ODBError):
  34. """Thrown if a possibly shortened name does not uniquely represent a single object
  35. in the database"""
  36. class BadObjectType(ODBError):
  37. """The object had an unsupported type"""
  38. class UnsupportedOperation(ODBError):
  39. """Thrown if the given operation cannot be supported by the object database"""