From df2fb548040c8313f4bb98870788604bc973fa18 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Tue, 27 Sep 2016 17:23:53 +0200 Subject: PY2, #519: FIX GitCommandError.tostr() encoding issue + PY3 means "PY3 or later" (TODO: fix also for *gitdb* project). --- git/exc.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'git/exc.py') diff --git a/git/exc.py b/git/exc.py index 34382ecd..3a93c447 100644 --- a/git/exc.py +++ b/git/exc.py @@ -6,8 +6,7 @@ """ Module containing all exceptions thrown througout the git package, """ from gitdb.exc import * # NOQA - -from git.compat import defenc +from git.compat import UnicodeMixin, safe_decode class InvalidGitRepositoryError(Exception): @@ -28,7 +27,7 @@ class GitCommandNotFound(Exception): pass -class GitCommandError(Exception): +class GitCommandError(UnicodeMixin, Exception): """ Thrown if execution of the git command fails with non-zero status code. """ def __init__(self, command, status, stderr=None, stdout=None): @@ -37,13 +36,13 @@ class GitCommandError(Exception): self.status = status self.command = command - def __str__(self): - ret = "'%s' returned with exit code %i" % \ - (' '.join(str(i) for i in self.command), self.status) + def __unicode__(self): + ret = u"'%s' returned with exit code %s" % \ + (u' '.join(safe_decode(i) for i in self.command), self.status) if self.stderr: - ret += "\nstderr: '%s'" % self.stderr.decode(defenc) + ret += u"\nstderr: '%s'" % safe_decode(self.stderr) if self.stdout: - ret += "\nstdout: '%s'" % self.stdout.decode(defenc) + ret += u"\nstdout: '%s'" % safe_decode(self.stdout) return ret -- cgit v1.2.1 From cf2335af23fb693549d6c4e72b65f97afddc5f64 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 28 Sep 2016 01:47:49 +0200 Subject: Win, hook, #519: Consume Hook Popen-proc out of GIL + HookException thrown on Popen, and were missed on Windows. + No SHELL on Popen?? + Minor fixes: + Try harder to delete trees - no remorses. + Simplify exception reprs. + Unittest-ize test_index assertions. --- git/exc.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'git/exc.py') diff --git a/git/exc.py b/git/exc.py index 3a93c447..37712d11 100644 --- a/git/exc.py +++ b/git/exc.py @@ -37,13 +37,9 @@ class GitCommandError(UnicodeMixin, Exception): self.command = command def __unicode__(self): - ret = u"'%s' returned with exit code %s" % \ - (u' '.join(safe_decode(i) for i in self.command), self.status) - if self.stderr: - ret += u"\nstderr: '%s'" % safe_decode(self.stderr) - if self.stdout: - ret += u"\nstdout: '%s'" % safe_decode(self.stdout) - return ret + cmdline = u' '.join(safe_decode(i) for i in self.command) + return (u"'%s' returned with exit code %s\n stdout: '%s'\n stderr: '%s'" + % (cmdline, self.status, safe_decode(self.stdout), safe_decode(self.stderr))) class CheckoutError(Exception): @@ -80,19 +76,20 @@ class UnmergedEntriesError(CacheError): entries in the cache""" -class HookExecutionError(Exception): +class HookExecutionError(UnicodeMixin, Exception): """Thrown if a hook exits with a non-zero exit code. It provides access to the exit code and the string returned via standard output""" - def __init__(self, command, status, stdout, stderr): + def __init__(self, command, status, stdout=None, stderr=None): self.command = command self.status = status self.stdout = stdout self.stderr = stderr - def __str__(self): - return ("'%s' hook returned with exit code %i\nstdout: '%s'\nstderr: '%s'" - % (self.command, self.status, self.stdout, self.stderr)) + def __unicode__(self): + cmdline = u' '.join(safe_decode(i) for i in self.command) + return (u"'%s' hook failed with %r\n stdout: '%s'\n stderr: '%s'" + % (cmdline, self.status, safe_decode(self.stdout), safe_decode(self.stderr))) class RepositoryDirtyError(Exception): -- cgit v1.2.1 From 44c6d0b368bc1ec6cd0a97b01678b38788c9bd9c Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 28 Sep 2016 05:46:50 +0200 Subject: Proc, #519: Rework error-exc msgs & log thread-pumps errors + No WindowsError exception. + Add `test_exc.py` for unicode issues. + Single-arg for decoding-streams in pump-func. --- git/exc.py | 72 +++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 24 deletions(-) (limited to 'git/exc.py') diff --git a/git/exc.py b/git/exc.py index 37712d11..6c9cde34 100644 --- a/git/exc.py +++ b/git/exc.py @@ -6,7 +6,7 @@ """ Module containing all exceptions thrown througout the git package, """ from gitdb.exc import * # NOQA -from git.compat import UnicodeMixin, safe_decode +from git.compat import UnicodeMixin, safe_decode, string_types class InvalidGitRepositoryError(Exception): @@ -21,25 +21,56 @@ class NoSuchPathError(OSError): """ Thrown if a path could not be access by the system. """ -class GitCommandNotFound(Exception): +class CommandError(UnicodeMixin, Exception): + """Base class for exceptions thrown at every stage of `Popen()` execution. + + :param command: + A non-empty list of argv comprising the command-line. + """ + + #: A unicode print-format with 2 `%s for `` and the rest, + #: e.g. + #: u"'%s' failed%s" + _msg = u"Cmd('%s') failed%s" + + def __init__(self, command, status=None, stderr=None, stdout=None): + assert isinstance(command, (tuple, list)), command + self.command = command + self.status = status + if status: + if isinstance(status, Exception): + status = u"%s('%s')" % (type(status).__name__, safe_decode(str(status))) + else: + try: + status = u'exit code(%s)' % int(status) + except: + s = safe_decode(str(status)) + status = u"'%s'" % s if isinstance(status, string_types) else s + + self._cmd = safe_decode(command[0]) + self._cmdline = u' '.join(safe_decode(i) for i in command) + self._cause = status and u" due to: %s" % status or "!" + self.stdout = stdout and u"\n stdout: '%s'" % safe_decode(stdout) or '' + self.stderr = stderr and u"\n stderr: '%s'" % safe_decode(stderr) or '' + + def __unicode__(self): + return (self._msg + "\n cmdline: %s%s%s") % ( + self._cmd, self._cause, self._cmdline, self.stdout, self.stderr) + + +class GitCommandNotFound(CommandError): """Thrown if we cannot find the `git` executable in the PATH or at the path given by the GIT_PYTHON_GIT_EXECUTABLE environment variable""" - pass + def __init__(self, command, cause): + super(GitCommandNotFound, self).__init__(command, cause) + self._msg = u"Cmd('%s') not found%s" -class GitCommandError(UnicodeMixin, Exception): +class GitCommandError(CommandError): """ Thrown if execution of the git command fails with non-zero status code. """ def __init__(self, command, status, stderr=None, stdout=None): - self.stderr = stderr - self.stdout = stdout - self.status = status - self.command = command - - def __unicode__(self): - cmdline = u' '.join(safe_decode(i) for i in self.command) - return (u"'%s' returned with exit code %s\n stdout: '%s'\n stderr: '%s'" - % (cmdline, self.status, safe_decode(self.stdout), safe_decode(self.stderr))) + super(GitCommandError, self).__init__(command, status, stderr, stdout) class CheckoutError(Exception): @@ -76,20 +107,13 @@ class UnmergedEntriesError(CacheError): entries in the cache""" -class HookExecutionError(UnicodeMixin, Exception): +class HookExecutionError(CommandError): """Thrown if a hook exits with a non-zero exit code. It provides access to the exit code and the string returned via standard output""" - def __init__(self, command, status, stdout=None, stderr=None): - self.command = command - self.status = status - self.stdout = stdout - self.stderr = stderr - - def __unicode__(self): - cmdline = u' '.join(safe_decode(i) for i in self.command) - return (u"'%s' hook failed with %r\n stdout: '%s'\n stderr: '%s'" - % (cmdline, self.status, safe_decode(self.stdout), safe_decode(self.stderr))) + def __init__(self, command, status, stderr=None, stdout=None): + super(HookExecutionError, self).__init__(command, status, stderr, stdout) + self._msg = u"Hook('%s') failed%s" class RepositoryDirtyError(Exception): -- cgit v1.2.1 From 6e98416791566f44a407dcac07a1e1f1b0483544 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 28 Sep 2016 17:10:59 +0200 Subject: remote, #519: INCOMPLETE FIX-2 double-decoding push-infos + Unicode PY2/3 issues fixed also in pump stream func. --- git/exc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/exc.py') diff --git a/git/exc.py b/git/exc.py index 6c9cde34..47215c21 100644 --- a/git/exc.py +++ b/git/exc.py @@ -34,7 +34,8 @@ class CommandError(UnicodeMixin, Exception): _msg = u"Cmd('%s') failed%s" def __init__(self, command, status=None, stderr=None, stdout=None): - assert isinstance(command, (tuple, list)), command + if not isinstance(command, (tuple, list)): + command = command.split() self.command = command self.status = status if status: -- cgit v1.2.1