Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1814f1c

Browse files
committed
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 "<string>", line 1, in <module> 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 "<string>", line 1, in <module> 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 "<string>", line 1, in <module> 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 ```
1 parent c9614de commit 1814f1c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _read_until(self, terminator):
9292
while True:
9393
c = self._proc.stdout.read(1)
9494
if not c:
95-
raise _ConverterError
95+
raise _ConverterError(os.fsdecode(bytes(buf)))
9696
buf.extend(c)
9797
if buf.endswith(terminator):
9898
return bytes(buf)
@@ -109,7 +109,8 @@ def __call__(self, orig, dest):
109109
try:
110110
self._read_until(b"\nGS")
111111
except _ConverterError as err:
112-
raise OSError("Failed to start Ghostscript") from err
112+
raise OSError(
113+
"Failed to start Ghostscript:\n\n" + err.args[0]) from None
113114

114115
def encode_and_escape(name):
115116
return (os.fsencode(name)
@@ -172,8 +173,9 @@ def __call__(self, orig, dest):
172173
try:
173174
self._read_until(terminator)
174175
except _ConverterError as err:
175-
raise OSError("Failed to start Inkscape in interactive "
176-
"mode") from err
176+
raise OSError(
177+
"Failed to start Inkscape in interactive mode:\n\n"
178+
+ err.args[0]) from err
177179

178180
# Inkscape's shell mode does not support escaping metacharacters in the
179181
# filename ("\n", and ":;" for inkscape>=1). Avoid any problems by

0 commit comments

Comments
 (0)