diff options
author | Ram Rachum <ram@rachum.com> | 2020-06-12 19:00:36 +0300 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-06-13 17:42:52 +0800 |
commit | 99ba753b837faab0509728ee455507f1a682b471 (patch) | |
tree | 5340a06b64d60550e66d509c92b78c9b018a6b00 /git | |
parent | 4720e6337bb14f24ec0b2b4a96359a9460dadee4 (diff) | |
download | gitpython-99ba753b837faab0509728ee455507f1a682b471.tar.gz |
Fix exception causes in 7 modules
Diffstat (limited to 'git')
-rw-r--r-- | git/refs/symbolic.py | 8 | ||||
-rw-r--r-- | git/remote.py | 12 | ||||
-rw-r--r-- | git/repo/base.py | 4 | ||||
-rw-r--r-- | git/repo/fun.py | 14 | ||||
-rw-r--r-- | git/test/test_base.py | 4 | ||||
-rw-r--r-- | git/test/test_config.py | 4 | ||||
-rw-r--r-- | git/util.py | 14 |
7 files changed, 31 insertions, 29 deletions
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index ee006cbc..550464e5 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -219,8 +219,8 @@ class SymbolicReference(object): else: try: invalid_type = self.repo.rev_parse(commit).type != Commit.type - except (BadObject, BadName): - raise ValueError("Invalid object: %s" % commit) + except (BadObject, BadName) as e: + raise ValueError("Invalid object: %s" % commit) from e # END handle exception # END verify type @@ -301,8 +301,8 @@ class SymbolicReference(object): try: obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags write_value = obj.hexsha - except (BadObject, BadName): - raise ValueError("Could not extract object from %s" % ref) + except (BadObject, BadName) as e: + raise ValueError("Could not extract object from %s" % ref) from e # END end try string else: raise ValueError("Unrecognized Value: %r" % ref) diff --git a/git/remote.py b/git/remote.py index d4180134..37c0ccd3 100644 --- a/git/remote.py +++ b/git/remote.py @@ -146,8 +146,8 @@ class PushInfo(object): # control character handling try: flags |= cls._flag_map[control_character] - except KeyError: - raise ValueError("Control character %r unknown as parsed from line %r" % (control_character, line)) + except KeyError as e: + raise ValueError("Control character %r unknown as parsed from line %r" % (control_character, line)) from e # END handle control character # from_to handling @@ -296,15 +296,15 @@ class FetchInfo(object): try: _new_hex_sha, _fetch_operation, fetch_note = fetch_line.split("\t") ref_type_name, fetch_note = fetch_note.split(' ', 1) - except ValueError: # unpack error - raise ValueError("Failed to parse FETCH_HEAD line: %r" % fetch_line) + except ValueError as e: # unpack error + raise ValueError("Failed to parse FETCH_HEAD line: %r" % fetch_line) from e # parse flags from control_character flags = 0 try: flags |= cls._flag_map[control_character] - except KeyError: - raise ValueError("Control character %r unknown as parsed from line %r" % (control_character, line)) + except KeyError as e: + raise ValueError("Control character %r unknown as parsed from line %r" % (control_character, line)) from e # END control char exception handling # parse operation string for more info - makes no sense for symbolic refs, but we parse it anyway diff --git a/git/repo/base.py b/git/repo/base.py index feb5934f..a7ca5ec6 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -341,8 +341,8 @@ class Repo(object): :raise ValueError: If no such submodule exists""" try: return self.submodules[name] - except IndexError: - raise ValueError("Didn't find submodule named %r" % name) + except IndexError as e: + raise ValueError("Didn't find submodule named %r" % name) from e # END exception handling def create_submodule(self, *args, **kwargs): diff --git a/git/repo/fun.py b/git/repo/fun.py index 9d9f8454..714d4122 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -251,16 +251,16 @@ def rev_parse(repo, rev): try: # transform reversed index into the format of our revlog revlog_index = -(int(output_type) + 1) - except ValueError: + except ValueError as e: # TODO: Try to parse the other date options, using parse_date # maybe - raise NotImplementedError("Support for additional @{...} modes not implemented") + raise NotImplementedError("Support for additional @{...} modes not implemented") from e # END handle revlog index try: entry = ref.log_entry(revlog_index) - except IndexError: - raise IndexError("Invalid revlog index: %i" % revlog_index) + except IndexError as e: + raise IndexError("Invalid revlog index: %i" % revlog_index) from e # END handle index out of bound obj = Object.new_from_sha(repo, hex_to_bin(entry.newhexsha)) @@ -324,8 +324,10 @@ def rev_parse(repo, rev): else: raise ValueError("Invalid token: %r" % token) # END end handle tag - except (IndexError, AttributeError): - raise BadName("Invalid revision spec '%s' - not enough parent commits to reach '%s%i'" % (rev, token, num)) + except (IndexError, AttributeError) as e: + raise BadName( + "Invalid revision spec '%s' - not enough " + "parent commits to reach '%s%i'" % (rev, token, num)) from e # END exception handling # END parse loop diff --git a/git/test/test_base.py b/git/test/test_base.py index 9cbbcf23..9da7c471 100644 --- a/git/test/test_base.py +++ b/git/test/test_base.py @@ -129,8 +129,8 @@ class TestBase(TestBase): # verify first that we could encode file name in this environment try: file_path.encode(sys.getfilesystemencoding()) - except UnicodeEncodeError: - raise SkipTest("Environment doesn't support unicode filenames") + except UnicodeEncodeError as e: + raise SkipTest("Environment doesn't support unicode filenames") from e with open(file_path, "wb") as fp: fp.write(b'something') diff --git a/git/test/test_config.py b/git/test/test_config.py index ce7a2cde..8418299f 100644 --- a/git/test/test_config.py +++ b/git/test/test_config.py @@ -98,10 +98,10 @@ class TestBase(TestCase): assert r_config.get_value('diff', 'tool') == "meld" try: assert r_config.get_value('sec', 'var1') == "value1_main" - except AssertionError: + except AssertionError as e: raise SkipTest( 'Known failure -- included values are not in effect right away' - ) + ) from e @with_rw_directory def test_lock_reentry(self, rw_dir): diff --git a/git/util.py b/git/util.py index ef4db04c..d8671107 100644 --- a/git/util.py +++ b/git/util.py @@ -94,7 +94,7 @@ def rmtree(path): func(path) # Will scream if still not possible to delete. 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 return shutil.rmtree(path, False, onerror) @@ -746,7 +746,7 @@ class LockFile(object): fd = os.open(lock_file, flags, 0) os.close(fd) except OSError as e: - raise IOError(str(e)) + raise IOError(str(e)) from e self._owns_lock = True @@ -801,19 +801,19 @@ class BlockingLockFile(LockFile): while True: try: super(BlockingLockFile, self)._obtain_lock() - except IOError: + except IOError as e: # synity check: if the directory leading to the lockfile is not # readable anymore, raise an exception curtime = time.time() if not osp.isdir(osp.dirname(self._lock_file_path())): msg = "Directory containing the lockfile %r was not readable anymore after waiting %g seconds" % ( self._lock_file_path(), curtime - starttime) - raise IOError(msg) + raise IOError(msg) from e # END handle missing directory if curtime >= maxtime: msg = "Waited %g seconds for lock at %r" % (maxtime - starttime, self._lock_file_path()) - raise IOError(msg) + raise IOError(msg) from e # END abort if we wait too long time.sleep(self._check_interval) else: @@ -878,8 +878,8 @@ class IterableList(list): try: return getattr(self, index) - except AttributeError: - raise IndexError("No item found with id %r" % (self._prefix + index)) + except AttributeError as e: + raise IndexError("No item found with id %r" % (self._prefix + index)) from e # END handle getattr def __delitem__(self, index): |