summaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
authorRam Rachum <ram@rachum.com>2020-06-13 23:29:59 +0300
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-06-14 08:30:09 +0800
commit411635f78229cdec26167652d44434bf8aa309ab (patch)
tree1e301ce6bdd458d4db20c993695bb763d1b9d158 /git
parent99ba753b837faab0509728ee455507f1a682b471 (diff)
downloadgitpython-411635f78229cdec26167652d44434bf8aa309ab.tar.gz
Fix exception causes all over the codebase
Diffstat (limited to 'git')
-rw-r--r--git/__init__.py8
-rw-r--r--git/db.py4
-rw-r--r--git/index/base.py6
-rw-r--r--git/index/fun.py2
-rw-r--r--git/objects/submodule/base.py24
-rw-r--r--git/objects/tree.py4
-rw-r--r--git/objects/util.py4
7 files changed, 26 insertions, 26 deletions
diff --git a/git/__init__.py b/git/__init__.py
index 8f32d07b..50730742 100644
--- a/git/__init__.py
+++ b/git/__init__.py
@@ -23,8 +23,8 @@ def _init_externals():
try:
import gitdb
- except ImportError:
- raise ImportError("'gitdb' could not be found in your PYTHONPATH")
+ except ImportError as e:
+ raise ImportError("'gitdb' could not be found in your PYTHONPATH") from e
# END verify import
#} END initialization
@@ -54,7 +54,7 @@ try:
rmtree,
)
except GitError as exc:
- raise ImportError('%s: %s' % (exc.__class__.__name__, exc))
+ raise ImportError('%s: %s' % (exc.__class__.__name__, exc)) from exc
#} END imports
@@ -82,5 +82,5 @@ def refresh(path=None):
try:
refresh()
except Exception as exc:
- raise ImportError('Failed to initialize: {0}'.format(exc))
+ raise ImportError('Failed to initialize: {0}'.format(exc)) from exc
#################
diff --git a/git/db.py b/git/db.py
index 9b334528..de2e9991 100644
--- a/git/db.py
+++ b/git/db.py
@@ -53,8 +53,8 @@ class GitCmdObjectDB(LooseObjectDB):
try:
hexsha, _typename, _size = self._git.get_object_header(partial_hexsha)
return hex_to_bin(hexsha)
- except (GitCommandError, ValueError):
- raise BadObject(partial_hexsha)
+ except (GitCommandError, ValueError) as e:
+ raise BadObject(partial_hexsha) from e
# END handle exceptions
#} END interface
diff --git a/git/index/base.py b/git/index/base.py
index 46974239..02299275 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -420,9 +420,9 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
rval = None
try:
proc.stdin.write(("%s\n" % filepath).encode(defenc))
- except IOError:
+ except IOError as e:
# pipe broke, usually because some error happened
- raise fmakeexc()
+ raise fmakeexc() from e
# END write exception handling
proc.stdin.flush()
if read_from_stdout:
@@ -954,7 +954,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
if not skip_hooks:
run_commit_hook('post-commit', self)
return rval
-
+
def _write_commit_editmsg(self, message):
with open(self._commit_editmsg_filepath(), "wb") as commit_editmsg_file:
commit_editmsg_file.write(message.encode(defenc))
diff --git a/git/index/fun.py b/git/index/fun.py
index c6337909..e92e8e38 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -82,7 +82,7 @@ def run_commit_hook(name, index, *args):
close_fds=is_posix,
creationflags=PROC_CREATIONFLAGS,)
except Exception as ex:
- raise HookExecutionError(hp, ex)
+ raise HookExecutionError(hp, ex) from ex
else:
stdout = []
stderr = []
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 4629f82d..722d341c 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -121,9 +121,9 @@ class Submodule(IndexObject, Iterable, Traversable):
# default submodule values
try:
self.path = reader.get('path')
- except cp.NoSectionError:
+ except cp.NoSectionError as e:
raise ValueError("This submodule instance does not exist anymore in '%s' file"
- % osp.join(self.repo.working_tree_dir, '.gitmodules'))
+ % osp.join(self.repo.working_tree_dir, '.gitmodules')) from e
# end
self._url = reader.get('url')
# git-python extension values - optional
@@ -189,9 +189,9 @@ class Submodule(IndexObject, Iterable, Traversable):
assert parent_commit is not None, "need valid parent_commit in bare repositories"
try:
fp_module = cls._sio_modules(parent_commit)
- except KeyError:
+ except KeyError as e:
raise IOError("Could not find %s file in the tree of parent commit %s" %
- (cls.k_modules_file, parent_commit))
+ (cls.k_modules_file, parent_commit)) from e
# END handle exceptions
# END handle non-bare working tree
@@ -516,9 +516,9 @@ class Submodule(IndexObject, Iterable, Traversable):
if not dry_run and osp.isdir(checkout_module_abspath):
try:
os.rmdir(checkout_module_abspath)
- except OSError:
+ except OSError as e:
raise OSError("Module directory at %r does already exist and is non-empty"
- % checkout_module_abspath)
+ % checkout_module_abspath) from e
# END handle OSError
# END handle directory removal
@@ -737,8 +737,8 @@ class Submodule(IndexObject, Iterable, Traversable):
del(index.entries[ekey])
nentry = git.IndexEntry(entry[:3] + (module_checkout_path,) + entry[4:])
index.entries[tekey] = nentry
- except KeyError:
- raise InvalidGitRepositoryError("Submodule's entry at %r did not exist" % (self.path))
+ except KeyError as e:
+ raise InvalidGitRepositoryError("Submodule's entry at %r did not exist" % (self.path)) from e
# END handle submodule doesn't exist
# update configuration
@@ -871,7 +871,7 @@ class Submodule(IndexObject, Iterable, Traversable):
rmtree(wtd)
except Exception as ex:
if HIDE_WINDOWS_KNOWN_ERRORS:
- raise SkipTest("FIXME: fails with: PermissionError\n {}".format(ex))
+ raise SkipTest("FIXME: fails with: PermissionError\n {}".format(ex)) from ex
raise
# END delete tree if possible
# END handle force
@@ -882,7 +882,7 @@ class Submodule(IndexObject, Iterable, Traversable):
rmtree(git_dir)
except Exception as ex:
if HIDE_WINDOWS_KNOWN_ERRORS:
- raise SkipTest("FIXME: fails with: PermissionError\n %s", ex)
+ raise SkipTest("FIXME: fails with: PermissionError\n %s", ex) from ex
else:
raise
# end handle separate bare repository
@@ -1046,8 +1046,8 @@ class Submodule(IndexObject, Iterable, Traversable):
if repo != self.repo:
return repo
# END handle repo uninitialized
- except (InvalidGitRepositoryError, NoSuchPathError):
- raise InvalidGitRepositoryError("No valid repository at %s" % module_checkout_abspath)
+ except (InvalidGitRepositoryError, NoSuchPathError) as e:
+ raise InvalidGitRepositoryError("No valid repository at %s" % module_checkout_abspath) from e
else:
raise InvalidGitRepositoryError("Repository at %r was not yet checked out" % module_checkout_abspath)
# END handle exceptions
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 469e5395..68e98329 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -203,8 +203,8 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
path = join_path(self.path, name)
try:
yield self._map_id_to_type[mode >> 12](self.repo, binsha, mode, path)
- except KeyError:
- raise TypeError("Unknown mode %o found in tree data for path '%s'" % (mode, path))
+ except KeyError as e:
+ raise TypeError("Unknown mode %o found in tree data for path '%s'" % (mode, path)) from e
# END for each item
def join(self, file):
diff --git a/git/objects/util.py b/git/objects/util.py
index 235b520e..b02479b7 100644
--- a/git/objects/util.py
+++ b/git/objects/util.py
@@ -203,8 +203,8 @@ def parse_date(string_date):
# still here ? fail
raise ValueError("no format matched")
# END handle format
- except Exception:
- raise ValueError("Unsupported date format: %s" % string_date)
+ except Exception as e:
+ raise ValueError("Unsupported date format: %s" % string_date) from e
# END handle exceptions