8000 Use custom exception to carry sha1 of the missing obj · gitpython-developers/GitPython@919022a · GitHub
[go: up one dir, main page]

Skip to content

Commit 919022a

Browse files
committed
Use custom exception to carry sha1 of the missing obj
I need to be able to detect what object is missing so that I can go ask the server for it and try again. One reason I tend to like creating my own custom exceptions is that they can carry context appropriate information about what went wrong. However, I can also see that it is more work.
1 parent c7eb6e7 commit 919022a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

git/cmd.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()):
147147
else 0)
148148

149149

150+
class MissingObject(ValueError):
151+
def __init__(self, sha1, *args, **kwargs):
152+
super(MissingObject, self).__init__(*args, **kwargs)
153+
self.sha1 = sha1
154+
155+
150156
class Git(LazyMixin):
151157

152158
"""
@@ -1023,7 +1029,7 @@ def _parse_object_header(self, header_line):
10231029
if not tokens:
10241030
raise ValueError("SHA could not be resolved, git returned: %r" % (header_line.strip()))
10251031
else:
1026-
raise ValueError("SHA %s could not be resolved, git returned: %r" % (tokens[0], header_line.strip()))
1032+
raise MissingObject(tokens[0], "SHA %s could not be resolved, git returned: %r" % (tokens[0], header_line.strip()))
10271033
# END handle actual return value
10281034
# END error handling
10291035

0 commit comments

Comments
 (0)
0