[Git][reproducible-builds/diffoscope][master] 3 commits: Skip extra newline in "Output:\n<none>".

Chris Lamb gitlab at salsa.debian.org
Sat Jul 13 18:11:41 UTC 2019



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
2bf55916 by Chris Lamb at 2019-07-13T17:53:42Z
Skip extra newline in "Output:\n<none>".

- - - - -
fc262f26 by Chris Lamb at 2019-07-13T18:02:47Z
Re-add "return code" noun to "Command `foo` exited with X" error messages.

- - - - -
f2c87dfc by Chris Lamb at 2019-07-13T18:09:11Z
If a command fails to execute but does not print anything to standard error, try and include the first line of standard output in the message we include in the diff. This was motivated by readelf(1) returning its error messages on stdout. (Closes: #931963, reproducible-builds/diffoscope#59)

- - - - -


2 changed files:

- diffoscope/comparators/utils/file.py
- diffoscope/feeders.py


Changes:

=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -437,16 +437,18 @@ class File(object, metaclass=abc.ABCMeta):
                     )
             except subprocess.CalledProcessError as e:
                 difference = self.compare_bytes(other, source=source)
-                if e.output:
-                    output = re.sub(r'^', '    ', e.output, flags=re.MULTILINE)
-                else:
-                    output = '<none>'
                 cmd = ' '.join(e.cmd)
                 if difference is None:
                     return None
+                output = '<none>'
+                if e.output:
+                    output = '\n{}'.format(
+                        re.sub(r'^', '    ', e.output, flags=re.MULTILINE)
+                    )
                 difference.add_comment(
-                    "Command `%s` exited with %d. Output:\n%s"
-                    % (cmd, e.returncode, output)
+                    "Command `{}` exited with return code {}. Output: {}".format(
+                        cmd, e.returncode, output
+                    )
                 )
             except RequiredToolNotFound as e:
                 difference = self.compare_bytes(other, source=source)


=====================================
diffoscope/feeders.py
=====================================
@@ -92,8 +92,17 @@ def from_command(command):
             end_nl = feeder(out_file)
             returncode = command.returncode
         if returncode not in (0, -signal.SIGTERM):
+            # On error, default to displaying all lines of standard output.
+            output = command.stderr
+            if not output and command.stdout:
+                # ... but if we don't have, return the first line of the
+                # standard output.
+                output = '{}{}'.format(
+                    command.stdout[0].decode('utf-8', 'ignore').strip(),
+                    '\n[…]' if len(command.stdout) > 1 else '',
+                )
             raise subprocess.CalledProcessError(
-                returncode, command.cmdline(), output=command.stderr
+                returncode, command.cmdline(), output=output
             )
         return end_nl
 



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/9414852a158851611e8ec30af4f9eb7c8ffdfe93...f2c87dfc225b8cd54485a535c135597b97314b98

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/9414852a158851611e8ec30af4f9eb7c8ffdfe93...f2c87dfc225b8cd54485a535c135597b97314b98
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20190713/7a3f2848/attachment.html>


More information about the rb-commits mailing list