8000 Tweak _ConverterError reporting. by anntzer · Pull Request #22791 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Tweak _ConverterError reporting. #22791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2022
Merged

Tweak _ConverterError reporting. #22791

merged 1 commit into from
Apr 6, 2022

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Apr 6, 2022

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

Inspired by #22768; should probably wait for that one to go in first to prevent a rebase, unless @tacaswell is OK with doing the rebase in the other direction.

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
< 8000 /option>

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
```
Copy link
Member
@oscargus oscargus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice with tests, but not a dealbreaker.

@anntzer
Copy link
Contributor Author
anntzer commented Apr 6, 2022

I did think very briefly about that, but didn't have an easy way to cause e.g. inkscape or ghostscript init to fail (which would be needed to test that this works fine). Complex contraptions are possible (e.g. make the command 8000 line args passed to either process be configurable and intentionally pass in incorrect args), but this seems a bit too complicated to be worth it?

@tacaswell tacaswell added this to the v3.6.0 milestone Apr 6, 2022
@tacaswell
Copy link
Member

I agree that while testing everything is good, in this case this is sad-paths in calling external programs as part of our testing. Given that this is not general user facing, if you are running this your are already doing something related to development work, and even with the better error messages you are in for a debugging session one way or the other I'm comfortable merging this as-is.

@tacaswell tacaswell merged commit 574580c into matplotlib:main Apr 6, 2022
@oscargus
Copy link
Member
oscargus commented Apr 6, 2022

OK! I was under the impression that one could simply do something like the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0