[1.1.3] run as runnable jar: traceback returns NullPointer

We are trying to use the library traceback to take some error from a try..except. But when we use the traceback.format_exc() we get a java.lang.NullPointerException.

Do you know how to solve this? Because I thought about not existing in Jython, but exists.

Obs. We are using a old version of Sikuli, version 1.1.3.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Patrick Geovani Francisconi Zerbinatti
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Please give a sample snippet

Revision history for this message
Patrick Geovani Francisconi Zerbinatti (pzerbinatti) said (last edit ):
#2

Sorry, I didn't found a option to add in the attachment the traceback.

But while I was codoing a sample snippet to explain better the problem, I found more clues about it.

In the Sikuli IDE I wrote the code:

import traceback

try:
    teste = 10/0
except:
    print(traceback.format_exc())

When I click on the button "Run" its work fine, returning the traceback about the division by zero. But when I use the option on "File" "Export as runnable jar" and try to execute the .jar from CMD it returns the java.lang.NullPointerException.

Obs. Another thing is my java is the 11

This is the full error:

Exception in thread "MainThread" Traceback (most recent call last):
  File "__pyclasspath__/__run__$py.class", line 4, in <module>
  File "__pyclasspath__/testeteste$py.class", line 7, in <module>
  File "C:\Users\pzerbinarri\Desktop\testeteste_sikuli.jar\Lib\traceback.py", line 241, in format_exc
  File "C:\Users\pzerbinarri\Desktop\testeteste_sikuli.jar\Lib\traceback.py", line 141, in format_exception
  File "C:\Users\pzerbinarri\Desktop\testeteste_sikuli.jar\Lib\traceback.py", line 76, in format_tb
  File "C:\Users\pzerbinarri\Desktop\testeteste_sikuli.jar\Lib\traceback.py", line 101, in extract_tb
  File "C:\Users\pzerbinarri\Desktop\testeteste_sikuli.jar\Lib\linecache.py", line 14, in getline
  File "C:\Users\pzerbinarri\Desktop\testeteste_sikuli.jar\Lib\linecache.py", line 40, in getlines
  File "C:\Users\pzerbinarri\Desktop\testeteste_sikuli.jar\Lib\linecache.py", line 92, in updatecache
  File "C:\Users\pzerbinarri\Desktop\testeteste_sikuli.jar\Lib\linecache.py", line 92, in updatecache
java.lang.NullPointerException
        at org.python.core.ClasspathPyImporter$1.close(ClasspathPyImporter.java:186)
        at org.python.core.ClasspathPyImporter.ClasspathPyImporter_get_source(ClasspathPyImporter.java:116)
        at org.python.core.ClasspathPyImporter$ClasspathPyImporter_get_source_exposer.__call__(Unknown Source)
        at org.python.core.PyObject.__call__(PyObject.java:484)
        at linecache$py.updatecache$5(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/linecache.py:135)
        at linecache$py.call_function(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/linecache.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
        at org.python.core.PyFunction.__call__(PyFunction.java:423)
        at linecache$py.getlines$3(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/linecache.py:40)
        at linecache$py.call_function(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/linecache.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
        at org.python.core.PyFunction.__call__(PyFunction.java:423)
        at linecache$py.getline$1(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/linecache.py:18)
        at linecache$py.call_function(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/linecache.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:171)
        at org.python.core.PyFunction.__call__(PyFunction.java:434)
        at traceback$py.extract_tb$6(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/traceback.py:107)
        at traceback$py.call_function(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/traceback.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
        at org.python.core.PyFunction.__call__(PyFunction.java:423)
        at traceback$py.format_tb$5(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/traceback.py:76)
        at traceback$py.call_function(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/traceback.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
        at org.python.core.PyFunction.__call__(PyFunction.java:423)
        at traceback$py.format_exception$8(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/traceback.py:145)
        at traceback$py.call_function(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/traceback.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:189)
        at org.python.core.PyFunction.__call__(PyFunction.java:446)
        at traceback$py.format_exc$14(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/traceback.py:243)
        at traceback$py.call_function(C:/Users/pzerbinarri/Desktop/testeteste_sikuli.jar/Lib/traceback.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:308)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:119)
        at org.python.core.PyFunction.__call__(PyFunction.java:403)
        at testeteste$py.f$0(C:/Users/pzerbinarri/AppData/Roaming/Sikulix/SetupStuff/scriptCompiled/testeteste.py:7)
        at testeteste$py.call_function(C:/Users/pzerbinarri/AppData/Roaming/Sikulix/SetupStuff/scriptCompiled/testeteste.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.imp.createFromCode(imp.java:436)
        at org.python.core.util.importer.importer_load_module(importer.java:116)
        at org.python.core.ClasspathPyImporter.ClasspathPyImporter_load_module(ClasspathPyImporter.java:170)
        at org.python.core.ClasspathPyImporter$ClasspathPyImporter_load_module_exposer.__call__(Unknown Source)
        at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:46)
        at org.python.core.imp.loadFromLoader(imp.java:593)
        at org.python.core.imp.find_module(imp.java:547)
        at org.python.core.imp.import_next(imp.java:838)
        at org.python.core.imp.import_module_level(imp.java:957)
        at org.python.core.imp.importName(imp.java:1057)
        at org.python.core.ImportFunction.__call__(__builtin__.java:1280)
        at org.python.core.PyObject.__call__(PyObject.java:450)
        at org.python.core.__builtin__.__import__(__builtin__.java:1232)
        at org.python.core.imp.importOne(imp.java:1076)
        at __run__$py.f$0(C:/Users/pzerbinarri/AppData/Roaming/Sikulix/SetupStuff/scriptCompiled/__run__.py:4)
        at __run__$py.call_function(C:/Users/pzerbinarri/AppData/Roaming/Sikulix/SetupStuff/scriptCompiled/__run__.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.imp.createFromCode(imp.java:436)
        at org.python.core.util.importer.importer_load_module(importer.java:116)
        at org.python.core.ClasspathPyImporter.ClasspathPyImporter_load_module(ClasspathPyImporter.java:170)
        at org.python.core.ClasspathPyImporter$ClasspathPyImporter_load_module_exposer.__call__(Unknown Source)
        at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:46)
        at org.python.core.imp.loadFromLoader(imp.java:593)
        at org.python.core.imp.find_module(imp.java:547)
        at org.python.core.imp.import_next(imp.java:838)
        at org.python.core.imp.import_first(imp.java:863)
        at org.python.core.imp.load(imp.java:721)
        at org.python.util.JarRunner.run(JarRunner.java:27)
        at org.python.util.JarRunner.main(JarRunner.java:31)
java.lang.NullPointerException: java.lang.NullPointerException

Revision history for this message
RaiMan (raimund-hocke) said :
#3

I am sorry, but I do not support 1.1.3 anymore with such special problems like runnable jar.

In actual versions, the feature "export as runnable jar" is not supported anyways.

I am not sure, whether the feature will come back in the next time.

You have to find another solution.

Revision history for this message
Patrick Geovani Francisconi Zerbinatti (pzerbinatti) said :
#4

Alright we tested with the last Sikuli version and it works fine. But we realise that its not the way we want the traceback, because in this case they will show the error line """"wrong"""", because after they "change" the file.

So, what is the right way to get other exceptions traceback besides the FindFailed?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

ok, just tested your case with 2.0.5 on Win 11:
When run from the runnable jar, there seems to be a problem with the stack trace, since it reports the exception cause correctly, but the line reference points to some line in the traceback module.

So as mentioned: it does not work, but I have to leave you alone with that.

You have to find another solution, to pack and run your scripts.

Revision history for this message
Patrick Geovani Francisconi Zerbinatti (pzerbinatti) said :
#6

No problem we will probably use sys.exc_info() with "except:", its not the better solution and not even the best practice, but its the better for now.

We are planning to migrate to the Sikuli using the Robot Framework, so its ok for this old code.

Thanks for now RaiMan!