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."""
25 class ChecksumMismatch(Exception):
26 """A checksum didn't match the expected contents."""
28 def __init__(self, expected, got, extra=None):
29 if len(expected) == 20:
30 expected = binascii.hexlify(expected)
32 got = binascii.hexlify(got)
33 self.expected = expected
36 if self.extra is None:
37 Exception.__init__(self,
38 "Checksum mismatch: Expected %s, got %s" % (expected, got))
40 Exception.__init__(self,
41 "Checksum mismatch: Expected %s, got %s; %s" %
42 (expected, got, extra))
45 class WrongObjectException(Exception):
46 """Baseclass for all the _ is not a _ exceptions on objects.
48 Do not instantiate directly.
50 Subclasses should define a type_name attribute that indicates what
51 was expected if they were raised.
54 def __init__(self, sha, *args, **kwargs):
55 Exception.__init__(self, "%s is not a %s" % (sha, self.type_name))
58 class NotCommitError(WrongObjectException):
59 """Indicates that the sha requested does not point to a commit."""
64 class NotTreeError(WrongObjectException):
65 """Indicates that the sha requested does not point to a tree."""
70 class NotTagError(WrongObjectException):
71 """Indicates that the sha requested does not point to a tag."""
76 class NotBlobError(WrongObjectException):
77 """Indicates that the sha requested does not point to a blob."""
82 class MissingCommitError(Exception):
83 """Indicates that a commit was not found in the repository"""
85 def __init__(self, sha, *args, **kwargs):
86 Exception.__init__(self, "%s is not in the revision store" % sha)
89 class ObjectMissing(Exception):
90 """Indicates that a requested object is missing."""
92 def __init__(self, sha, *args, **kwargs):
93 Exception.__init__(self, "%s is not in the pack" % sha)
96 class ApplyDeltaError(Exception):
97 """Indicates that applying a delta failed."""
99 def __init__(self, *args, **kwargs):
100 Exception.__init__(self, *args, **kwargs)
103 class NotGitRepository(Exception):
104 """Indicates that no Git repository was found."""
106 def __init__(self, *args, **kwargs):
107 Exception.__init__(self, *args, **kwargs)
110 class GitProtocolError(Exception):
111 """Git protocol exception."""
113 def __init__(self, *args, **kwargs):
114 Exception.__init__(self, *args, **kwargs)
117 class SendPackError(GitProtocolError):
118 """An error occurred during send_pack."""
120 def __init__(self, *args, **kwargs):
121 Exception.__init__(self, *args, **kwargs)
124 class UpdateRefsError(GitProtocolError):
125 """The server reported errors updating refs."""
127 def __init__(self, *args, **kwargs):
128 self.ref_status = kwargs.pop('ref_status')
129 Exception.__init__(self, *args, **kwargs)
132 class HangupException(GitProtocolError):
133 """Hangup exception."""
136 Exception.__init__(self,
137 "The remote server unexpectedly closed the connection.")
140 class FileFormatException(Exception):
141 """Base class for exceptions relating to reading git file formats."""
144 class PackedRefsException(FileFormatException):
145 """Indicates an error parsing a packed-refs file."""
148 class ObjectFormatException(FileFormatException):
149 """Indicates an error parsing an object."""
152 class NoIndexPresent(Exception):
153 """No index is present."""
156 class CommitError(Exception):
157 """An error occurred while performing a commit."""