# Raise descriptive error for broken display install (GitHub afw #516)

XMLWordPrintable

#### Details

• Type: Story
• Status: In Review
• Resolution: Unresolved
• Fix Version/s: None
• Component/s:
• Labels:
None
• Story Points:
1
• Team:
• Urgent?:
No

#### Description

On GitHub afw #516, Brigitta Sipocz writes:

Consider the following code and the scenario of the 'matplotlib' backend and a broken install where lsst.display is not available.
https://github.com/lsst/afw/blob/master/python/lsst/afw/display/interface.py#L85-L106

It raises the somewhat cryptic error message:

RuntimeError: Unable to set backend to matplotlib: "module 'matplotlib' has no attribute 'DisplayImpl'"

While the real underlying issue is that lsst.display is not available, matplotlib should never be expected to have a DisplayImpl attribute.

My naive approach of shuffling the order of elements in the tuple probably makes no sense, adding another try/except might be enough to raise a more relevant error.

Let me know if you would like a quick PR. (The install has since been fixed, so I won't have a good way to test it).

#### Activity

Hide
John Swinbank added a comment - - edited

Robert Lupton, could you take a quick look at https://github.com/lsst/afw/pull/517 please?

I think the bulk of the changes (on 60bae5c) are straightforward enough.

However, I'd really appreciate a sanity check on 8a7392a. This is removing a display argument from a docstring which you added a couple of years ago, but which it seems to me can't have been right then (and certainly isn't now)... but I'm not sure what you were aiming for! Can you help?

Show
John Swinbank added a comment - - edited Robert Lupton , could you take a quick look at https://github.com/lsst/afw/pull/517 please? I think the bulk of the changes (on 60bae5c ) are straightforward enough. However, I'd really appreciate a sanity check on 8a7392a . This is removing a display argument from a docstring which you added a couple of years ago , but which it seems to me can't have been right then (and certainly isn't now)... but I'm not sure what you were aiming for! Can you help?
Hide
John Swinbank added a comment -

Hi Robert Lupton — any chance you'll have a few minutes to look at this? If not, please let me know and I'll find somebody else. Thanks!

Show
John Swinbank added a comment - Hi Robert Lupton — any chance you'll have a few minutes to look at this? If not, please let me know and I'll find somebody else. Thanks!
Hide
Robert Lupton added a comment -

I don't see an easy way to reproduce this – a broken install seems a bit out of scope.  Given a how-to-repeat I'd be happy to generate a better error message

Show
Robert Lupton added a comment - I don't see an easy way to reproduce this – a broken install seems a bit out of scope.  Given a how-to-repeat I'd be happy to generate a better error message
Hide
John Swinbank added a comment -

The install doesn't really need to be broken; that's a bit of a red-herring. The following should work to reproduce:

 [swinbank@lsst-dev01 ~]$. /software/lsstsw/stack/loadLSST.bash [swinbank@lsst-dev01 ~]$ setup afw [swinbank@lsst-dev01 ~]$python -c 'import lsst.afw.display as afwDisplay; afwDisplay.Display.setDefaultBackend("matplotlib")' Traceback (most recent call last):  File "/software/lsstsw/stack_20200515/stack/miniconda3-4.7.12-46b24e8/Linux64/afw/19.0.0-25-g6c8df7140+1/python/lsst/afw/display/interface.py", line 267, in setDefaultBackend  _makeDisplayImpl(None, backend)  File "/software/lsstsw/stack_20200515/stack/miniconda3-4.7.12-46b24e8/Linux64/afw/19.0.0-25-g6c8df7140+1/python/lsst/afw/display/interface.py", line 100, in _makeDisplayImpl  if not _disp or not hasattr(_disp.DisplayImpl, "_show"): AttributeError: module 'matplotlib' has no attribute 'DisplayImpl'   During handling of the above exception, another exception occurred:   Traceback (most recent call last):  File "", line 1, in   File "/software/lsstsw/stack_20200515/stack/miniconda3-4.7.12-46b24e8/Linux64/afw/19.0.0-25-g6c8df7140+1/python/lsst/afw/display/interface.py", line 270, in setDefaultBackend  f"Unable to set backend to {backend}: \"{e}\"") RuntimeError: Unable to set backend to matplotlib: "module 'matplotlib' has no attribute 'DisplayImpl'"  The fix I asked you to review changes that AttributeError to:  ImportError: Could not load the requested backend: matplotlib (tried lsst.display.matplotlib, matplotlib, .matplotlib, lsst.afw.display.matplotlib, but none worked).  That's still not ideal, but I think it's less immediately baffling than the stuff about DisplayImpl. Suggestions for an alternative wording that makes clear “we tried to import a bunch of different things, but they either didn't exist or weren't appropriate” much appreciated! Show John Swinbank added a comment - The install doesn't really need to be broken; that's a bit of a red-herring. The following should work to reproduce: [swinbank@lsst-dev01 ~]$ . /software/lsstsw/stack/loadLSST.bash [swinbank@lsst-dev01 ~]$setup afw [swinbank@lsst-dev01 ~]$ python -c 'import lsst.afw.display as afwDisplay; afwDisplay.Display.setDefaultBackend("matplotlib")' Traceback (most recent call last): File "/software/lsstsw/stack_20200515/stack/miniconda3-4.7.12-46b24e8/Linux64/afw/19.0.0-25-g6c8df7140+1/python/lsst/afw/display/interface.py", line 267, in setDefaultBackend _makeDisplayImpl(None, backend) File "/software/lsstsw/stack_20200515/stack/miniconda3-4.7.12-46b24e8/Linux64/afw/19.0.0-25-g6c8df7140+1/python/lsst/afw/display/interface.py", line 100, in _makeDisplayImpl if not _disp or not hasattr(_disp.DisplayImpl, "_show"): AttributeError: module 'matplotlib' has no attribute 'DisplayImpl'   During handling of the above exception, another exception occurred:   Traceback (most recent call last): File "<string>", line 1, in <module> File "/software/lsstsw/stack_20200515/stack/miniconda3-4.7.12-46b24e8/Linux64/afw/19.0.0-25-g6c8df7140+1/python/lsst/afw/display/interface.py", line 270, in setDefaultBackend f"Unable to set backend to {backend}: \"{e}\"") RuntimeError: Unable to set backend to matplotlib: "module 'matplotlib' has no attribute 'DisplayImpl'" The fix I asked you to review changes that AttributeError to: ImportError: Could not load the requested backend: matplotlib (tried lsst.display.matplotlib, matplotlib, .matplotlib, lsst.afw.display.matplotlib, but none worked). That's still not ideal, but I think it's less immediately baffling than the stuff about DisplayImpl . Suggestions for an alternative wording that makes clear “we tried to import a bunch of different things, but they either didn't exist or weren't appropriate” much appreciated!
Hide
John Swinbank added a comment -

Robert Lupton — I propose to merge this as-is before I bow out of the project in a few days. If you object, please shout now.

Show
John Swinbank added a comment - Robert Lupton — I propose to merge this as-is before I bow out of the project in a few days. If you object, please shout now.
Hide
Tim Jenness added a comment -

Robert Lupton shall I merge this clean up since John Swinbank is no longer around to do it?

Show
Tim Jenness added a comment - Robert Lupton shall I merge this clean up since John Swinbank is no longer around to do it?
Hide
Tim Jenness added a comment -

Ian Sullivan did you become the assignee of this ticket by default because it was John Swinbank?

Show
Tim Jenness added a comment - Ian Sullivan did you become the assignee of this ticket by default because it was John Swinbank ?

#### People

Assignee:
Ian Sullivan
Reporter:
John Swinbank
Reviewers:
Robert Lupton
Watchers:
John Swinbank, Monika Adamow, Robert Lupton, Tim Jenness