Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/dulwich/errors.py: 60%
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# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
7# General Public License as published by the Free Software Foundation; version 2.0
8# or (at your option) any later version. You can redistribute it and/or
9# modify it under the terms of either of these two licenses.
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# You should have received a copy of the licenses; if not, see
18# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
19# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
20# License, Version 2.0.
21#
23"""Dulwich-related exception classes and utility functions."""
26# Please do not add more errors here, but instead add them close to the code
27# that raises the error.
29import binascii
32class ChecksumMismatch(Exception):
33 """A checksum didn't match the expected contents."""
35 def __init__(self, expected, got, extra=None) -> None:
36 if len(expected) == 20:
37 expected = binascii.hexlify(expected)
38 if len(got) == 20:
39 got = binascii.hexlify(got)
40 self.expected = expected
41 self.got = got
42 self.extra = extra
43 message = f"Checksum mismatch: Expected {expected}, got {got}"
44 if self.extra is not None:
45 message += f"; {extra}"
46 Exception.__init__(self, message)
49class WrongObjectException(Exception):
50 """Baseclass for all the _ is not a _ exceptions on objects.
52 Do not instantiate directly.
54 Subclasses should define a type_name attribute that indicates what
55 was expected if they were raised.
56 """
58 type_name: str
60 def __init__(self, sha, *args, **kwargs) -> None:
61 Exception.__init__(self, f"{sha} is not a {self.type_name}")
64class NotCommitError(WrongObjectException):
65 """Indicates that the sha requested does not point to a commit."""
67 type_name = "commit"
70class NotTreeError(WrongObjectException):
71 """Indicates that the sha requested does not point to a tree."""
73 type_name = "tree"
76class NotTagError(WrongObjectException):
77 """Indicates that the sha requested does not point to a tag."""
79 type_name = "tag"
82class NotBlobError(WrongObjectException):
83 """Indicates that the sha requested does not point to a blob."""
85 type_name = "blob"
88class MissingCommitError(Exception):
89 """Indicates that a commit was not found in the repository."""
91 def __init__(self, sha, *args, **kwargs) -> None:
92 self.sha = sha
93 Exception.__init__(self, f"{sha} is not in the revision store")
96class ObjectMissing(Exception):
97 """Indicates that a requested object is missing."""
99 def __init__(self, sha, *args, **kwargs) -> None:
100 Exception.__init__(self, f"{sha} is not in the pack")
103class ApplyDeltaError(Exception):
104 """Indicates that applying a delta failed."""
106 def __init__(self, *args, **kwargs) -> None:
107 Exception.__init__(self, *args, **kwargs)
110class NotGitRepository(Exception):
111 """Indicates that no Git repository was found."""
113 def __init__(self, *args, **kwargs) -> None:
114 Exception.__init__(self, *args, **kwargs)
117class GitProtocolError(Exception):
118 """Git protocol exception."""
120 def __init__(self, *args, **kwargs) -> None:
121 Exception.__init__(self, *args, **kwargs)
123 def __eq__(self, other):
124 return isinstance(self, type(other)) and self.args == other.args
127class SendPackError(GitProtocolError):
128 """An error occurred during send_pack."""
131class HangupException(GitProtocolError):
132 """Hangup exception."""
134 def __init__(self, stderr_lines=None) -> None:
135 if stderr_lines:
136 super().__init__(
137 "\n".join(
138 line.decode("utf-8", "surrogateescape") for line in stderr_lines
139 )
140 )
141 else:
142 super().__init__("The remote server unexpectedly closed the connection.")
143 self.stderr_lines = stderr_lines
145 def __eq__(self, other):
146 return isinstance(self, type(other)) and self.stderr_lines == other.stderr_lines
149class UnexpectedCommandError(GitProtocolError):
150 """Unexpected command received in a proto line."""
152 def __init__(self, command) -> None:
153 command_str = "flush-pkt" if command is None else f"command {command}"
154 super().__init__(f"Protocol got unexpected {command_str}")
157class FileFormatException(Exception):
158 """Base class for exceptions relating to reading git file formats."""
161class PackedRefsException(FileFormatException):
162 """Indicates an error parsing a packed-refs file."""
165class ObjectFormatException(FileFormatException):
166 """Indicates an error parsing an object."""
169class NoIndexPresent(Exception):
170 """No index is present."""
173class CommitError(Exception):
174 """An error occurred while performing a commit."""
177class RefFormatError(Exception):
178 """Indicates an invalid ref name."""
181class HookError(Exception):
182 """An error occurred while executing a hook."""
185class WorkingTreeModifiedError(Exception):
186 """Indicates that the working tree has modifications that would be overwritten."""