errors.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # errors.py -- errors for dulwich
  2. # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # or (at your option) any later version of the License.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. # MA 02110-1301, USA.
  18. """Dulwich-related exception classes and utility functions."""
  19. class ChecksumMismatch(Exception):
  20. """A checksum didn't match the expected contents."""
  21. def __init__(self, expected, got, extra=None):
  22. self.expected = expected
  23. self.got = got
  24. self.extra = extra
  25. if self.extra is None:
  26. Exception.__init__(self,
  27. "Checksum mismatch: Expected %s, got %s" % (expected, got))
  28. else:
  29. Exception.__init__(self,
  30. "Checksum mismatch: Expected %s, got %s; %s" %
  31. (expected, got, extra))
  32. class WrongObjectException(Exception):
  33. """Baseclass for all the _ is not a _ exceptions on objects.
  34. Do not instantiate directly.
  35. Subclasses should define a _type attribute that indicates what
  36. was expected if they were raised.
  37. """
  38. def __init__(self, sha, *args, **kwargs):
  39. string = "%s is not a %s" % (sha, self._type)
  40. Exception.__init__(self, string)
  41. class NotCommitError(WrongObjectException):
  42. """Indicates that the sha requested does not point to a commit."""
  43. _type = 'commit'
  44. class NotTreeError(WrongObjectException):
  45. """Indicates that the sha requested does not point to a tree."""
  46. _type = 'tree'
  47. class NotBlobError(WrongObjectException):
  48. """Indicates that the sha requested does not point to a blob."""
  49. _type = 'blob'
  50. class MissingCommitError(Exception):
  51. """Indicates that a commit was not found in the repository"""
  52. def __init__(self, sha, *args, **kwargs):
  53. Exception.__init__(self, "%s is not in the revision store" % sha)
  54. class ObjectMissing(Exception):
  55. """Indicates that a requested object is missing."""
  56. def __init__(self, sha, *args, **kwargs):
  57. Exception.__init__(self, "%s is not in the pack" % sha)
  58. class ApplyDeltaError(Exception):
  59. """Indicates that applying a delta failed."""
  60. def __init__(self, *args, **kwargs):
  61. Exception.__init__(self, *args, **kwargs)
  62. class NotGitRepository(Exception):
  63. """Indicates that no Git repository was found."""
  64. def __init__(self, *args, **kwargs):
  65. Exception.__init__(self, *args, **kwargs)
  66. class GitProtocolError(Exception):
  67. """Git protocol exception."""
  68. def __init__(self, *args, **kwargs):
  69. Exception.__init__(self, *args, **kwargs)
  70. class HangupException(GitProtocolError):
  71. """Hangup exception."""