errors.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 WrongObjectException(Exception):
  20. """Baseclass for all the _ is not a _ exceptions on objects.
  21. Do not instantiate directly.
  22. Subclasses should define a _type attribute that indicates what
  23. was expected if they were raised.
  24. """
  25. def __init__(self, sha, *args, **kwargs):
  26. string = "%s is not a %s" % (sha, self._type)
  27. Exception.__init__(self, string)
  28. class NotCommitError(WrongObjectException):
  29. """Indicates that the sha requested does not point to a commit."""
  30. _type = 'commit'
  31. class NotTreeError(WrongObjectException):
  32. """Indicates that the sha requested does not point to a tree."""
  33. _type = 'tree'
  34. class NotBlobError(WrongObjectException):
  35. """Indicates that the sha requested does not point to a blob."""
  36. _type = 'blob'
  37. class MissingCommitError(Exception):
  38. """Indicates that a commit was not found in the repository"""
  39. def __init__(self, sha, *args, **kwargs):
  40. Exception.__init__(self, "%s is not in the revision store" % sha)
  41. class ObjectMissing(Exception):
  42. """Indicates that a requested object is missing."""
  43. def __init__(self, sha, *args, **kwargs):
  44. Exception.__init__(self, "%s is not in the pack" % sha)
  45. class ApplyDeltaError(Exception):
  46. """Indicates that applying a delta failed."""
  47. def __init__(self, *args, **kwargs):
  48. Exception.__init__(self, *args, **kwargs)
  49. class NotGitRepository(Exception):
  50. """Indicates that no Git repository was found."""
  51. def __init__(self, *args, **kwargs):
  52. Exception.__init__(self, *args, **kwargs)
  53. class GitProtocolError(Exception):
  54. """Git protocol exception."""
  55. def __init__(self, *args, **kwargs):
  56. Exception.__init__(self, *args, **kwargs)
  57. class HangupException(GitProtocolError):
  58. """Hangup exception."""