From 80d93a6289cca7324e2f4647c2fc21f243f79167 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 12 May 2022 10:48:46 +0200 Subject: [PATCH] Suppress traceback chaining for tex subprocess failures. For tex failures (e.g., `figtext(.5, .5, "\N{snowman}", usetex=True)`), instead of ``` Traceback (most recent call last): File ".../matplotlib/texmanager.py", line 253, in _run_checked_subprocess report = subprocess.check_output( File "/usr/lib/python3.10/subprocess.py", line 420, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib/python3.10/subprocess.py", line 524, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', '../71cab2b5aca12ed5cad4a481b3b00e42.tex']' returned non-zero exit status 1. The above exception was the direct cause of the following exception: Traceback (most recent call last): raise RuntimeError( RuntimeError: latex was not able to process the following string: b'\\u2603' Here is the full report generated by latex: This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) (preloaded format=latex) ``` instead report the failure in a single block, as ``` Traceback (most recent call last): raise RuntimeError( RuntimeError: latex was not able to process the following string: b'\\u2603' Here is the full command invocation and its output: latex -interaction=nonstopmode --halt-on-error ../71cab2b5aca12ed5cad4a481b3b00e42.tex This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) (preloaded format=latex) ``` (the exception chaining is not particularly informative, and we can move the only relevant info -- the command we tried to run -- to the second exception). --- lib/matplotlib/texmanager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 2ffe0d5f668e..d1b6d92b1689 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -261,11 +261,13 @@ def _run_checked_subprocess(cls, command, tex, *, cwd=None): raise RuntimeError( '{prog} was not able to process the following string:\n' '{tex!r}\n\n' - 'Here is the full report generated by {prog}:\n' + 'Here is the full command invocation and its output:\n\n' + '{format_command}\n\n' '{exc}\n\n'.format( prog=command[0], + format_command=cbook._pformat_subprocess(command), tex=tex.encode('unicode_escape'), - exc=exc.output.decode('utf-8'))) from exc + exc=exc.output.decode('utf-8'))) from None _log.debug(report) return report