Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/dulwich/errors.py: 59%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# errors.py -- errors for dulwich
2# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
3# Copyright (C) 2009-2012 Jelmer Vernooij <jelmer@jelmer.uk>
4#
5# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
6# General Public License as public by the Free Software Foundation; version 2.0
7# or (at your option) any later version. You can redistribute it and/or
8# modify it under the terms of either of these two licenses.
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# You should have received a copy of the licenses; if not, see
17# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
18# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
19# License, Version 2.0.
20#
22"""Dulwich-related exception classes and utility functions."""
25# Please do not add more errors here, but instead add them close to the code
26# that raises the error.
28import binascii
31class ChecksumMismatch(Exception):
32 """A checksum didn't match the expected contents."""
34 def __init__(self, expected, got, extra=None) -> None:
35 if len(expected) == 20:
36 expected = binascii.hexlify(expected)
37 if len(got) == 20:
38 got = binascii.hexlify(got)
39 self.expected = expected
40 self.got = got
41 self.extra = extra
42 if self.extra is None:
43 Exception.__init__(
44 self,
45 f"Checksum mismatch: Expected {expected}, got {got}",
46 )
47 else:
48 Exception.__init__(
49 self,
50 f"Checksum mismatch: Expected {expected}, got {got}; {extra}",
51 )
54class WrongObjectException(Exception):
55 """Baseclass for all the _ is not a _ exceptions on objects.
57 Do not instantiate directly.
59 Subclasses should define a type_name attribute that indicates what
60 was expected if they were raised.
61 """
63 type_name: str
65 def __init__(self, sha, *args, **kwargs) -> None:
66 Exception.__init__(self, f"{sha} is not a {self.type_name}")
69class NotCommitError(WrongObjectException):
70 """Indicates that the sha requested does not point to a commit."""
72 type_name = "commit"
75class NotTreeError(WrongObjectException):
76 """Indicates that the sha requested does not point to a tree."""
78 type_name = "tree"
81class NotTagError(WrongObjectException):
82 """Indicates that the sha requested does not point to a tag."""
84 type_name = "tag"
87class NotBlobError(WrongObjectException):
88 """Indicates that the sha requested does not point to a blob."""
90 type_name = "blob"
93class MissingCommitError(Exception):
94 """Indicates that a commit was not found in the repository."""
96 def __init__(self, sha, *args, **kwargs) -> None:
97 self.sha = sha
98 Exception.__init__(self, f"{sha} is not in the revision store")
101class ObjectMissing(Exception):
102 """Indicates that a requested object is missing."""
104 def __init__(self, sha, *args, **kwargs) -> None:
105 Exception.__init__(self, f"{sha} is not in the pack")
108class ApplyDeltaError(Exception):
109 """Indicates that applying a delta failed."""
111 def __init__(self, *args, **kwargs) -> None:
112 Exception.__init__(self, *args, **kwargs)
115class NotGitRepository(Exception):
116 """Indicates that no Git repository was found."""
118 def __init__(self, *args, **kwargs) -> None:
119 Exception.__init__(self, *args, **kwargs)
122class GitProtocolError(Exception):
123 """Git protocol exception."""
125 def __init__(self, *args, **kwargs) -> None:
126 Exception.__init__(self, *args, **kwargs)
128 def __eq__(self, other):
129 return isinstance(self, type(other)) and self.args == other.args
132class SendPackError(GitProtocolError):
133 """An error occurred during send_pack."""
136class HangupException(GitProtocolError):
137 """Hangup exception."""
139 def __init__(self, stderr_lines=None) -> None:
140 if stderr_lines:
141 super().__init__(
142 "\n".join(
143 [line.decode("utf-8", "surrogateescape") for line in stderr_lines]
144 )
145 )
146 else:
147 super().__init__("The remote server unexpectedly closed the connection.")
148 self.stderr_lines = stderr_lines
150 def __eq__(self, other):
151 return isinstance(self, type(other)) and self.stderr_lines == other.stderr_lines
154class UnexpectedCommandError(GitProtocolError):
155 """Unexpected command received in a proto line."""
157 def __init__(self, command) -> None:
158 if command is None:
159 command = "flush-pkt"
160 else:
161 command = f"command {command}"
162 super().__init__(f"Protocol got unexpected {command}")
165class FileFormatException(Exception):
166 """Base class for exceptions relating to reading git file formats."""
169class PackedRefsException(FileFormatException):
170 """Indicates an error parsing a packed-refs file."""
173class ObjectFormatException(FileFormatException):
174 """Indicates an error parsing an object."""
177class NoIndexPresent(Exception):
178 """No index is present."""
181class CommitError(Exception):
182 """An error occurred while performing a commit."""
185class RefFormatError(Exception):
186 """Indicates an invalid ref name."""
189class HookError(Exception):
190 """An error occurred while executing a hook."""