JunoLab / Juno.jl

MIT License
144 stars 23 forks source link

[BUG] value incorrectly displayed on error in `__init__` #546

Closed goretkin closed 4 years ago

goretkin commented 4 years ago

Sorry this is a heavyweight reproducer. First I thought this was Julia-specific, but I did not see this behavior when running outside of Atom.

Details

Steps to reproduce

module A
ENV["MPLBACKEND"]="bogus";

import PyCall
function __init__()
    @show length(methods(show))
    try
        PyCall.pyimport_conda("matplotlib", "matplotlib")
        # Once you have matplotlib installed, use this instead to go faster.
        # PyCall.pyimport("matplotlib")
    catch e
        show(e) # this is calling the right `show` method
        throw(e)
    end
end
end

Running the above file twice in Juno gives:

length(methods(show)) = 306
PyError (PyImport_ImportModule) <class 'ValueError'>
ValueError("Key backend: Unrecognized backend string 'bogus': valid strings are ['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']")
  File "/Users/goretkin/.julia/conda/3/lib/python3.7/site-packages/matplotlib/__init__.py", line 1317, in <module>
    rcParams['backend'] = os.environ.get('MPLBACKEND')
  File "/Users/goretkin/.julia/conda/3/lib/python3.7/site-packages/matplotlib/__init__.py", line 804, in __setitem__
    raise ValueError("Key %s: %s" % (key, str(ve)))
ERROR: InitError: PyCall.PyError("PyImport_ImportModule", PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x000000013ccea760), PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x000000014c87c9b0), PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x000000014c893640))
Stacktrace:
 [1] __init__() at /private/tmp/inittest.jl:14
during initialization of module A
WARNING: replacing module A.
306
PyError (PyImport_ImportModule) <class 'ValueError'>
ValueError("Key backend: Unrecognized backend string 'bogus': valid strings are ['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']")
  File "/Users/goretkin/.julia/conda/3/lib/python3.7/site-packages/matplotlib/__init__.py", line 1317, in <module>
    rcParams['backend'] = os.environ.get('MPLBACKEND')
  File "/Users/goretkin/.julia/conda/3/lib/python3.7/site-packages/matplotlib/__init__.py", line 804, in __setitem__
    raise ValueError("Key %s: %s" % (key, str(ve)))
ERROR: InitError: PyError (PyImport_ImportModule) <class 'ValueError'>
ValueError("Key backend: Unrecognized backend string 'bogus': valid strings are ['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']")
  File "/Users/goretkin/.julia/conda/3/lib/python3.7/site-packages/matplotlib/__init__.py", line 1317, in <module>
    rcParams['backend'] = os.environ.get('MPLBACKEND')
  File "/Users/goretkin/.julia/conda/3/lib/python3.7/site-packages/matplotlib/__init__.py", line 804, in __setitem__
    raise ValueError("Key %s: %s" % (key, str(ve)))

Stacktrace:
 [1] __init__() at /private/tmp/inittest.jl:14
during initialization of module A

I hope to draw your attention to the lines starting with "ERROR: InitError: " It is printed differently the first time (in a less helpful way). As far as I can tell, this was specific to __init__.

matplotlib is just an example that throws an error that has a specialized show method, which is obvious. Certainly any Python package that errors would do it. Sorry again for not having a slimmer reproducer.

pfitzseb commented 4 years ago

Seems likely we're missing a bunch of invokelatests somewhere.

pfitzseb commented 4 years ago

Fixed by https://github.com/JunoLab/Atom.jl/pull/313.