errors.py 3.6 KB

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