consistently use chunks internally inside of the pack code.
[jelmer/dulwich-libgit2.git] / dulwich / errors.py
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
20 """Dulwich-related exception classes and utility functions."""
21
22 class ChecksumMismatch(Exception):
23     """A checksum didn't match the expected contents."""
24
25     def __init__(self, expected, got, extra=None):
26         self.expected = expected
27         self.got = got
28         self.extra = extra
29         if self.extra is None:
30             Exception.__init__(self, 
31                 "Checksum mismatch: Expected %s, got %s" % (expected, got))
32         else:
33             Exception.__init__(self,
34                 "Checksum mismatch: Expected %s, got %s; %s" % 
35                 (expected, got, extra))
36
37
38 class WrongObjectException(Exception):
39     """Baseclass for all the _ is not a _ exceptions on objects.
40   
41     Do not instantiate directly.
42   
43     Subclasses should define a _type attribute that indicates what
44     was expected if they were raised.
45     """
46   
47     def __init__(self, sha, *args, **kwargs):
48         string = "%s is not a %s" % (sha, self._type)
49         Exception.__init__(self, string)
50
51
52 class NotCommitError(WrongObjectException):
53     """Indicates that the sha requested does not point to a commit."""
54   
55     _type = 'commit'
56
57
58 class NotTreeError(WrongObjectException):
59     """Indicates that the sha requested does not point to a tree."""
60   
61     _type = 'tree'
62
63
64 class NotTagError(WrongObjectException):
65     """Indicates that the sha requested does not point to a tag."""
66
67     _type = 'tag'
68
69
70 class NotBlobError(WrongObjectException):
71     """Indicates that the sha requested does not point to a blob."""
72   
73     _type = 'blob'
74
75
76 class MissingCommitError(Exception):
77     """Indicates that a commit was not found in the repository"""
78   
79     def __init__(self, sha, *args, **kwargs):
80         Exception.__init__(self, "%s is not in the revision store" % sha)
81
82
83 class ObjectMissing(Exception):
84     """Indicates that a requested object is missing."""
85   
86     def __init__(self, sha, *args, **kwargs):
87         Exception.__init__(self, "%s is not in the pack" % sha)
88
89
90 class ApplyDeltaError(Exception):
91     """Indicates that applying a delta failed."""
92     
93     def __init__(self, *args, **kwargs):
94         Exception.__init__(self, *args, **kwargs)
95
96
97 class NotGitRepository(Exception):
98     """Indicates that no Git repository was found."""
99
100     def __init__(self, *args, **kwargs):
101         Exception.__init__(self, *args, **kwargs)
102
103
104 class GitProtocolError(Exception):
105     """Git protocol exception."""
106     
107     def __init__(self, *args, **kwargs):
108         Exception.__init__(self, *args, **kwargs)
109
110
111 class HangupException(GitProtocolError):
112     """Hangup exception."""
113
114     def __init__(self):
115         Exception.__init__(self,
116             "The remote server unexpectedly closed the connection.")
117
118
119 class FileFormatException(Exception):
120     """Base class for exceptions relating to reading git file formats."""
121
122
123 class PackedRefsException(FileFormatException):
124     """Indicates an error parsing a packed-refs file."""
125
126
127 class NoIndexPresent(Exception):
128     """No index is present."""