errors.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_name attribute that indicates what
  37. was expected if they were raised.
  38. """
  39. def __init__(self, sha, *args, **kwargs):
  40. Exception.__init__(self, "%s is not a %s" % (sha, self.type_name))
  41. class NotCommitError(WrongObjectException):
  42. """Indicates that the sha requested does not point to a commit."""
  43. type_name = 'commit'
  44. class NotTreeError(WrongObjectException):
  45. """Indicates that the sha requested does not point to a tree."""
  46. type_name = 'tree'
  47. class NotTagError(WrongObjectException):
  48. """Indicates that the sha requested does not point to a tag."""
  49. type_name = 'tag'
  50. class NotBlobError(WrongObjectException):
  51. """Indicates that the sha requested does not point to a blob."""
  52. type_name = 'blob'
  53. class MissingCommitError(Exception):
  54. """Indicates that a commit was not found in the repository"""
  55. def __init__(self, sha, *args, **kwargs):
  56. Exception.__init__(self, "%s is not in the revision store" % sha)
  57. class ObjectMissing(Exception):
  58. """Indicates that a requested object is missing."""
  59. def __init__(self, sha, *args, **kwargs):
  60. Exception.__init__(self, "%s is not in the pack" % sha)
  61. class ApplyDeltaError(Exception):
  62. """Indicates that applying a delta failed."""
  63. def __init__(self, *args, **kwargs):
  64. Exception.__init__(self, *args, **kwargs)
  65. class NotGitRepository(Exception):
  66. """Indicates that no Git repository was found."""
  67. def __init__(self, *args, **kwargs):
  68. Exception.__init__(self, *args, **kwargs)
  69. class GitProtocolError(Exception):
  70. """Git protocol exception."""
  71. def __init__(self, *args, **kwargs):
  72. Exception.__init__(self, *args, **kwargs)
  73. class HangupException(GitProtocolError):
  74. """Hangup exception."""
  75. def __init__(self):
  76. Exception.__init__(self,
  77. "The remote server unexpectedly closed the connection.")
  78. class FileFormatException(Exception):
  79. """Base class for exceptions relating to reading git file formats."""
  80. class PackedRefsException(FileFormatException):
  81. """Indicates an error parsing a packed-refs file."""
  82. class ObjectFormatException(FileFormatException):
  83. """Indicates an error parsing an object."""
  84. class NoIndexPresent(Exception):
  85. """No index is present."""