From 1814f1cb7627fe86ee7f650a48772d360e4c306d Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 6 Apr 2022 10:53:11 +0200 Subject: [PATCH] Tweak _ConverterError reporting. Chaining an empty _ConverterError doesn't add useful info; instead, print out the output stream. e.g. modify _GSConverter to use the invalid `-sDEVICE=1234`; previously `_GSConverter()("foo", "bar")` would give: ``` Traceback (most recent call last): File ".../matplotlib/testing/compare.py", line 110, in __call__ self._read_until(b"\nGS") File ".../matplotlib/testing/compare.py", line 95, in _read_until raise _ConverterError matplotlib.testing.compare._ConverterError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "", line 1, in File "/home/antony/src/extern/matplotlib/lib/matplotlib/testing/compare.py", line 112, in __call__ raise OSError("Failed to start Ghostscript") from err OSError: Failed to start Ghostscript ``` or, if just passing buf as parameter when constructing the _ConverterError: ``` Traceback (most recent call last): File ".../matplotlib/testing/compare.py", line 110, in __call__ self._read_until(b"\nGS") File ".../matplotlib/testing/compare.py", line 95, in _read_until raise _ConverterError(buf) matplotlib.testing.compare._ConverterError: bytearray(b'GPL Ghostscript 9.55.0 (2021-09-27)\nCopyright (C) 2021 Artifex Software, Inc. All rights reserved.\nThis software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:\nsee the file COPYING for details.\nUnknown device: 1234\n') The above exception was the direct cause of the following exception: Traceback (most recent call last): File "", line 1, in File ".../matplotlib/testing/compare.py", line 112, in __call__ raise OSError("Failed to start Ghostscript") from err OSError: Failed to start Ghostscript ``` and now it gives: ``` Traceback (most recent call last): File "", line 1, in File ".../matplotlib/testing/compare.py", line 112, in __call__ raise OSError("Failed to start Ghostscript:\n\n" + err.args[0]) from None OSError: Failed to start Ghostscript: GPL Ghostscript 9.55.0 (2021-09-27) Copyright (C) 2021 Artifex Software, Inc. All rights reserved. This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY: see the file COPYING for details. Unknown device: 1234 ``` --- lib/matplotlib/testing/compare.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index e712dd05c360..0a2ae17b36d0 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -92,7 +92,7 @@ def _read_until(self, terminator): while True: c = self._proc.stdout.read(1) if not c: - raise _ConverterError + raise _ConverterError(os.fsdecode(bytes(buf))) buf.extend(c) if buf.endswith(terminator): return bytes(buf) @@ -109,7 +109,8 @@ def __call__(self, orig, dest): try: self._read_until(b"\nGS") except _ConverterError as err: - raise OSError("Failed to start Ghostscript") from err + raise OSError( + "Failed to start Ghostscript:\n\n" + err.args[0]) from None def encode_and_escape(name): return (os.fsencode(name) @@ -172,8 +173,9 @@ def __call__(self, orig, dest): try: self._read_until(terminator) except _ConverterError as err: - raise OSError("Failed to start Inkscape in interactive " - "mode") from err + raise OSError( + "Failed to start Inkscape in interactive mode:\n\n" + + err.args[0]) from err # Inkscape's shell mode does not support escaping metacharacters in the # filename ("\n", and ":;" for inkscape>=1). Avoid any problems by