How to enable full error traceback

Asked by Chp

Hi RaiMan.
Here is my code: http://joxi.ru/XYmEg7MiBvzyA6
______________________________________________
# coding=utf-8
import sys
from os.path import dirname
from os import putenv
from sikuli.Sikuli import getBundlePath

TEST_DIR = dirname(dirname(dirname(getBundlePath())))
ROOT_DIR = dirname(TEST_DIR)

putenv('TEST_DIR', TEST_DIR)
putenv('ROOT_DIR', ROOT_DIR)

sys.path.append(TEST_DIR)
sys.path.append(ROOT_DIR)

from Core import API, Common, Config
from TestCases.DW import DW
from TestCases.Objects import Building, Dragon, Interface
from sikuli.Sikuli import sleep

######## Local info ########

dw = DW("Breeding Cave test")
dw.bookmark = '#bookmark=kix.e5b4mg9n2ok2'
dw.set_user(Config.USERS_FB[3])
dw.admin.load(dw.user, 'Breeding')
dw.start()
____________________________________________

I specially made an error in class DW in method start(). After starting script I get trace:
[error] script [ D:\autotest\dragon_world\TestCases\Building\BreedingCave.sikuli ] stopped with error in line 27
[error] ZeroDivisionError ( integer division or modulo by zero )
Exception in thread "MainThread" java.lang.IllegalStateException: No match found
 at java.util.regex.Matcher.group(Matcher.java:536)
 at org.sikuli.scriptrunner.JythonScriptRunner.findErrorSourceWalkTrace(JythonScriptRunner.java:356)
 at org.sikuli.scriptrunner.JythonScriptRunner.findErrorSource(JythonScriptRunner.java:321)
 at org.sikuli.scriptrunner.JythonScriptRunner.runPython(JythonScriptRunner.java:226)
 at org.sikuli.scriptrunner.JythonScriptRunner.runScript(JythonScriptRunner.java:183)
 at org.sikuli.scriptrunner.ScriptingSupport$RunBox.run(ScriptingSupport.java:597)
 at org.sikuli.scriptrunner.ScriptingSupport$RunBox.access$400(ScriptingSupport.java:513)
 at org.sikuli.scriptrunner.ScriptingSupport.runscript(ScriptingSupport.java:442)
 at org.sikuli.ide.SikuliIDE.run(SikuliIDE.java:206)
 at org.sikuli.ide.Sikulix.main(Sikulix.java:21)

This trace shows that error caused in line 27 of my script. But this error is not in this line, it's in imported module. But trace do not show this and this is not comfortable.
In earlier versions of SIkuli trace was full and showed complete path to the error.
Also I have code:
def log_uncaught_exceptions(type, value, tb):
    error("\n" + "\n".join(traceback.format_tb(tb)) + str(value))

sys.excepthook = log_uncaught_exceptions

which was getting trace and log it in my filelog.txt. Now it does not work, because you changed something in trace output. Can I turn it off somehow and get complete trace to the error, because this is very uncomfortable for debugging? (Remain classic jython trace)

Question information

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

made it a bug for now. not sure when I will fix it.

meanwhile you should run your scripts from command line.

java -cp sikulix.jar org.python.util.jython yourScript.sikuli/yourScript.py

Take Care:
These pre-run statements are not processed on script run:
  "# -*- coding: utf-8 -*- ",
  "from sikuli import *",
  "use() #resetROI()",
  "setShowActions(False)"

... and the bundlePath is not set.

... or you should generally switch to Eclipse/PyDev for coding and only use the IDE for managing your images.

Revision history for this message
Chp (chpnick) said :
#2

I run skript from command line: D:\\Distributiv\\Sikuli\\Sikuli1.1\\runsikulix.cmd", "-r", "script_path", "--args", "home=1","eoe=1",

I work in IntelliJ IDEA, and I have everything works fine except for trace. If I try to run how you ask me, I must have something significant to change in my code? I'm sorry for my english

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

ok, then my suggestion makes no sense (you would have to change too many things in your coding).

I will have a look, wether I can add a switch so you get the normal output as you expect it.

The related bug will automatically send you a note, if I have done something that might help.

Revision history for this message
Chp (chpnick) said :
#4

I try to run as you say, and I have everything working, I changed a lot of things to upgrade to version 1.1. I understand I just need to do at the beginning of the script from sikuli.Sikuli import *. And I have earned and getBundlePath. Tell me whether I think about imports?

Revision history for this message
Chp (chpnick) said :
#5

example in run my script:
# coding=utf-8
import sys
from os.path import dirname
from os import putenv
from sikuli.Sikuli import getBundlePath

TEST_DIR = dirname(dirname(dirname(getBundlePath())))
ROOT_DIR = dirname(TEST_DIR)

putenv('TEST_DIR', TEST_DIR)
putenv('ROOT_DIR', ROOT_DIR)

sys.path.append(TEST_DIR)
sys.path.append(ROOT_DIR)

from Core import API, Common, Config
from TestCases.MeInt import MeInt
from TestCases.Objects import Interface, Building
from sikuli.Sikuli import sleep

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

the basic problem (not traceback info, only the line in the main script) should be fixed in tomorrows build.

--- sys.excepthook = log_uncaught_exceptions
... does not work in the Jython interpreter mode, that is used when you run scripts with the SikuliX IDE (from GUI or command line)

If you want to use this, you have to run the script with Jython directly.

example:

print "************** starting mainpy.sikuli"
import sys
from os.path import dirname
import traceback

def log_uncaught_exceptions(type, value, tb):
    print "*** exception_hook"
    for e in traceback.format_tb(tb): print e
    print "--- error"
    print str(value)

sys.excepthook = log_uncaught_exceptions

print "**** sys.argv"
for e in sys.argv: print e

print "*** sys.path"
dir = dirname(dirname(sys.argv[0]))
if not dir in sys.path: sys.path.append(dir)
for e in sys.path: print e

from subpy import *
func()

# content of subpy.py in same folder a s mainpy
print "import: subpy.py"
def func():
 1/0

--- a run command

java -Xmx512M -Dfile.encoding=UTF-8 -cp <path-to-sikulix.jar> org.python.util.jython <path-to-someScript.sikuli/someScript.py>

one might also install Jython separately and use the jython.bat after having prepared the environment accordingly.

Revision history for this message
Chp (chpnick) said :
#7

Thanks RaiMan, that solved my question.