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>
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.
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.
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,
20 """Dulwich-related exception classes and utility functions."""
22 class ChecksumMismatch(Exception):
23 """A checksum didn't match the expected contents."""
25 def __init__(self, expected, got, extra=None):
26 self.expected = expected
29 if self.extra is None:
30 Exception.__init__(self,
31 "Checksum mismatch: Expected %s, got %s" % (expected, got))
33 Exception.__init__(self,
34 "Checksum mismatch: Expected %s, got %s; %s" %
35 (expected, got, extra))
38 class WrongObjectException(Exception):
39 """Baseclass for all the _ is not a _ exceptions on objects.
41 Do not instantiate directly.
43 Subclasses should define a _type attribute that indicates what
44 was expected if they were raised.
47 def __init__(self, sha, *args, **kwargs):
48 string = "%s is not a %s" % (sha, self._type)
49 Exception.__init__(self, string)
52 class NotCommitError(WrongObjectException):
53 """Indicates that the sha requested does not point to a commit."""
58 class NotTreeError(WrongObjectException):
59 """Indicates that the sha requested does not point to a tree."""
64 class NotTagError(WrongObjectException):
65 """Indicates that the sha requested does not point to a tag."""
70 class NotBlobError(WrongObjectException):
71 """Indicates that the sha requested does not point to a blob."""
76 class MissingCommitError(Exception):
77 """Indicates that a commit was not found in the repository"""
79 def __init__(self, sha, *args, **kwargs):
80 Exception.__init__(self, "%s is not in the revision store" % sha)
83 class ObjectMissing(Exception):
84 """Indicates that a requested object is missing."""
86 def __init__(self, sha, *args, **kwargs):
87 Exception.__init__(self, "%s is not in the pack" % sha)
90 class ApplyDeltaError(Exception):
91 """Indicates that applying a delta failed."""
93 def __init__(self, *args, **kwargs):
94 Exception.__init__(self, *args, **kwargs)
97 class NotGitRepository(Exception):
98 """Indicates that no Git repository was found."""
100 def __init__(self, *args, **kwargs):
101 Exception.__init__(self, *args, **kwargs)
104 class GitProtocolError(Exception):
105 """Git protocol exception."""
107 def __init__(self, *args, **kwargs):
108 Exception.__init__(self, *args, **kwargs)
111 class HangupException(GitProtocolError):
112 """Hangup exception."""
115 Exception.__init__(self,
116 "The remote server unexpectedly closed the connection.")
119 class FileFormatException(Exception):
120 """Base class for exceptions relating to reading git file formats."""
123 class PackedRefsException(FileFormatException):
124 """Indicates an error parsing a packed-refs file."""
127 class NoIndexPresent(Exception):
128 """No index is present."""