Display exit code with InvocationErrors

Issue #290 on hold
Daniel Hahler created an issue

When a command fails, you currently only get ERROR: InvocationError: '/usr/bin/false', but the exitcode itself is useful/important, e.g. with py.test using 5 for "no tests collected".

The following patch would provide that, by using a custom __str__ method for InvocationError - but it does not handle the case where that might be missing (not all instances / calls to it provide it).

Maybe a custom __init__ should be used to set the arguments as properties explicitly, and then use them?!

diff -r e9569646da4f tox/__init__.py
--- a/tox/__init__.py   Wed Nov 25 12:27:48 2015 +0100
+++ b/tox/__init__.py   Wed Nov 25 13:23:26 2015 +0100
@@ -17,6 +17,9 @@
         "signals that an interpreter could not be found"
     class InvocationError(Error):
         """ an error while invoking a script. """
+        def __str__(self):
+            return "%s: %s (exitcode %d)" % (self.__class__.__name__,
+                                             self.args[0], self.args[1])
     class MissingFile(Error):
         """ an error while invoking a script. """
     class MissingDirectory(Error):

This is related / similar to https://bitbucket.org/hpk42/tox/issues/192.

Comments (6)

  1. Daniel Hahler reporter

    While at it, it might be useful to display it also here:

    diff -r e9569646da4f tox/venv.py
    --- a/tox/venv.py   Wed Nov 25 12:27:48 2015 +0100
    +++ b/tox/venv.py   Wed Nov 25 14:50:51 2015 +0100
    @@ -137,6 +137,7 @@
                 return sys.exc_info()[1]
             try:
                 self.install_deps(action)
    +        # TODO: display InvocationError here?
             except tox.exception.InvocationError:
                 v = sys.exc_info()[1]
                 return "could not install deps %s; v = %r" % (
    
  2. Daniel Hahler reporter

    Here is an updated patch that will pass tests at least:

    --- a/tox/__init__.py   Wed Nov 25 12:27:48 2015 +0100
    +++ b/tox/__init__.py   Wed Nov 25 18:37:41 2015 +0100
    @@ -17,6 +17,20 @@
             "signals that an interpreter could not be found"
         class InvocationError(Error):
             """ an error while invoking a script. """
    +        def __init__(self, *args):
    +            super(exception.Error, self).__init__(*args)
    +            self.command = args[0]
    +            try:
    +                self.exitcode = args[1]
    +            except IndexError:
    +                self.exitcode = None
    +
    +        def __str__(self):
    +            if self.exitcode:
    +                return "%s: %s (exitcode %d)" % (self.__class__.__name__,
    +                                                 self.command, self.exitcode)
    +            return "%s: %s" % (self.__class__.__name__, self.command)
    +
         class MissingFile(Error):
             """ an error while invoking a script. """
         class MissingDirectory(Error):
    
  3. Florian Bruhin

    +1 for this feature - I've had tests segfault and no useful info from tox before. I got used to it, but the first time I saw it it took me a while to figure out what happened.

  4. Log in to comment