clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.06k stars 69 forks source link

require-python hides useful python error messages #159

Closed behrica closed 2 years ago

behrica commented 3 years ago

By doing this

(libpython-clj2.require/require-python '[top2vec])

vs.

(py/import-module "top2vec")

the first hides the root cause of an issue with the module. Only the import-module prints this on the console:

Execution error at libpython-clj2.python/path->py-obj (python.clj:627).
Failed to find module or class top2Vec
Execution error at libpython-clj2.python.ffi/check-error-throw (ffi.clj:670).
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/top2vec/__init__.py", line 1, in <module>
    from top2vec.Top2Vec import Top2Vec
  File "/usr/local/lib/python3.9/site-packages/top2vec/Top2Vec.py", line 20, in <module>
    from tqdm import tqdm
ModuleNotFoundError: No module named 'tqdm'

while require-python only gives this stacktrace:

 Unhandled java.lang.Exception
   Failed to find module or class top2Vec

                python.clj:  627  libpython-clj2.python/path->py-obj
                python.clj:  608  libpython-clj2.python/path->py-obj
               RestFn.java:  439  clojure.lang.RestFn/invoke
               require.clj:  109  libpython-clj2.require/do-require-python
               require.clj:   86  libpython-clj2.require/do-require-python
               require.clj:  273  libpython-clj2.require/require-python/fn
               require.clj:  265  libpython-clj2.require/require-python
               require.clj:  173  libpython-clj2.require/require-
jjtolton commented 3 years ago

For clarification, does this occur from Python as well or only in libpython-clj?

On Thu, Apr 29, 2021 at 5:10 PM Carsten Behring @.***> wrote:

By doing this

(libpython-clj2.require/require-python '[top2Vec])

vs.

(py/import-module "top2vec")

the first hides the root cause of an issue with the module. Only the import-module prints this on the console:

Execution error at libpython-clj2.python/path->py-obj (python.clj:627). Failed to find module or class top2Vec Execution error at libpython-clj2.python.ffi/check-error-throw (ffi.clj:670). Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/top2vec/init.py", line 1, in from top2vec.Top2Vec import Top2Vec File "/usr/local/lib/python3.9/site-packages/top2vec/Top2Vec.py", line 20, in from tqdm import tqdm ModuleNotFoundError: No module named 'tqdm'

while require-python only gives this stacktrace:

Unhandled java.lang.Exception Failed to find module or class top2Vec

            python.clj:  627  libpython-clj2.python/path->py-obj
            python.clj:  608  libpython-clj2.python/path->py-obj
           RestFn.java:  439  clojure.lang.RestFn/invoke
           require.clj:  109  libpython-clj2.require/do-require-python
           require.clj:   86  libpython-clj2.require/do-require-python
           require.clj:  273  libpython-clj2.require/require-python/fn
           require.clj:  265  libpython-clj2.require/require-python
           require.clj:  173  libpython-clj2.require/require-

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/clj-python/libpython-clj/issues/159, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPJX43GIHYNLC3VDX3VSS3TLHDNVANCNFSM432W2UBQ .

cnuernber commented 3 years ago

I can confirm this happens. There is a try/catch in there in a perhaps inappropriate place. The work is to distinguish between attributes that won't load that we warn about and failures that we report to the user.

behrica commented 2 years ago

I got it again today. It hides really useful information. For me it was a missing module, and I spotted it easily seeing the full trace (from inside python shell)

jjtolton commented 2 years ago

Please see: https://github.com/clj-python/libpython-clj/pull/177

jjtolton commented 2 years ago

Whoops, still requires some work. I forgot all the magic we were doing here