Use ConfigParser for now
[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 NotBlobError(WrongObjectException):
65     """Indicates that the sha requested does not point to a blob."""
66   
67     _type = 'blob'
68
69
70 class MissingCommitError(Exception):
71     """Indicates that a commit was not found in the repository"""
72   
73     def __init__(self, sha, *args, **kwargs):
74         Exception.__init__(self, "%s is not in the revision store" % sha)
75
76
77 class ObjectMissing(Exception):
78     """Indicates that a requested object is missing."""
79   
80     def __init__(self, sha, *args, **kwargs):
81         Exception.__init__(self, "%s is not in the pack" % sha)
82
83
84 class ApplyDeltaError(Exception):
85     """Indicates that applying a delta failed."""
86     
87     def __init__(self, *args, **kwargs):
88         Exception.__init__(self, *args, **kwargs)
89
90
91 class NotGitRepository(Exception):
92     """Indicates that no Git repository was found."""
93
94     def __init__(self, *args, **kwargs):
95         Exception.__init__(self, *args, **kwargs)
96
97
98 class GitProtocolError(Exception):
99     """Git protocol exception."""
100     
101     def __init__(self, *args, **kwargs):
102         Exception.__init__(self, *args, **kwargs)
103
104
105 class HangupException(GitProtocolError):
106     """Hangup exception."""
107
108     def __init__(self):
109         Exception.__init__(self,
110             "The remote server unexpectedly closed the connection.")
111
112
113 class FileFormatException(Exception):
114     """Base class for exceptions relating to reading git file formats."""
115
116
117 class PackedRefsException(FileFormatException):
118     """Indicates an error parsing a packed-refs file."""
119
120
121 class NoIndexPresent(Exception):
122     """No index is present."""