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_name attribute that indicates what
44 was expected if they were raised.
47 def __init__(self, sha, *args, **kwargs):
48 Exception.__init__(self, "%s is not a %s" % (sha, self.type_name))
51 class NotCommitError(WrongObjectException):
52 """Indicates that the sha requested does not point to a commit."""
57 class NotTreeError(WrongObjectException):
58 """Indicates that the sha requested does not point to a tree."""
63 class NotTagError(WrongObjectException):
64 """Indicates that the sha requested does not point to a tag."""
69 class NotBlobError(WrongObjectException):
70 """Indicates that the sha requested does not point to a blob."""
75 class MissingCommitError(Exception):
76 """Indicates that a commit was not found in the repository"""
78 def __init__(self, sha, *args, **kwargs):
79 Exception.__init__(self, "%s is not in the revision store" % sha)
82 class ObjectMissing(Exception):
83 """Indicates that a requested object is missing."""
85 def __init__(self, sha, *args, **kwargs):
86 Exception.__init__(self, "%s is not in the pack" % sha)
89 class ApplyDeltaError(Exception):
90 """Indicates that applying a delta failed."""
92 def __init__(self, *args, **kwargs):
93 Exception.__init__(self, *args, **kwargs)
96 class NotGitRepository(Exception):
97 """Indicates that no Git repository was found."""
99 def __init__(self, *args, **kwargs):
100 Exception.__init__(self, *args, **kwargs)
103 class GitProtocolError(Exception):
104 """Git protocol exception."""
106 def __init__(self, *args, **kwargs):
107 Exception.__init__(self, *args, **kwargs)
110 class HangupException(GitProtocolError):
111 """Hangup exception."""
114 Exception.__init__(self,
115 "The remote server unexpectedly closed the connection.")
118 class FileFormatException(Exception):
119 """Base class for exceptions relating to reading git file formats."""
122 class PackedRefsException(FileFormatException):
123 """Indicates an error parsing a packed-refs file."""
126 class NoIndexPresent(Exception):
127 """No index is present."""