Kodi Community Forum

Full Version: traceback crash in kodi log
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
instead of logging a proper traceback when an addon crashes, traceback itself seems to crash...
i guess this is something that needs to be fixed in kodi?

Quote:19:43:13.232 T:139977184810752   ERROR: Traceback (most recent call last):
19:43:13.232 T:139977184810752   ERROR:   File "/usr/lib/python3.6/traceback.py", line 117, in format_exception
19:43:13.232 T:139977184810752   ERROR: type(value), value, tb, limit=limit).format(chain=chain))
19:43:13.232 T:139977184810752   ERROR:   File "/usr/lib/python3.6/traceback.py", line 465, in __init__
19:43:13.232 T:139977184810752   ERROR: if (exc_value and exc_value.__cause__ is not None
19:43:13.232 T:139977184810752   ERROR: AttributeError
19:43:13.232 T:139977184810752   ERROR: :
19:43:13.232 T:139977184810752   ERROR: 'str' object has no attribute '__cause__'
19:43:13.232 T:139977184810752   ERROR: CPythonInvoker(11, /home/ronie/.kodi/addons/script.test/default.py): failed to run the gc to clean up after running prior to shutting down the Interpreter


it's currently kind of hard to port addons to python 3 without having proper error logging ;-)
The following quick test has run with no issues:
try:
    raise RuntimeError
except RuntimeError:
    with web_pdb.catch_post_mortem():
        xbmc.log('Exception info: ' + traceback.format_exc())

Are you sure that you are raising a proper exception that is a class derived from Exception or an instance of such class?
it's not about try/except. ;-)

i'm just testing my addons in py3 and look at the log when they crash. that gives me an indication which parts of the code need to by updated for py3.

here's another example of such a crash:
Quote:01:56:11.251 T:140670127806208   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <class 'TypeError'>
                                            Error Contents: Unicode-objects must be encoded before hashing
                                            -->End of Python script error report<--
01:56:11.253 T:140670127806208   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <class 'SystemError'>
                                            Error Contents: <built-in function sleep> returned a result with an error set
                                            Traceback (most recent call last):
                                              File "/usr/lib/python3.6/traceback.py", line 117, in format_exception
                                                type(value), value, tb, limit=limit).format(chain=chain))
                                              File "/usr/lib/python3.6/traceback.py", line 465, in __init__
                                                if (exc_value and exc_value.__cause__ is not None
                                            AttributeError: 'str' object has no attribute '__cause__'
                                            
                                            The above exception was the direct cause of the following exception:
                                            
                                            Traceback (most recent call last):
                                              File "/home/ronie/.kodi/addons/service.scrobbler.librefm/scrobbler.py", line 333, in <module>
                                                Main()
                                              File "/home/ronie/.kodi/addons/service.scrobbler.librefm/scrobbler.py", line 40, in __init__
                                                xbmc.sleep(1000)
                                            SystemError: <built-in function sleep> returned a result with an error set
                                            -->End of Python script error report<--
01:56:11.269 T:140670127806208    INFO: Python script stopped
also, sometimes when a script crashes, i get no traceback at all...

import xbmcaddon

path = xbmcaddon.Addon().decode("utf-8")

kodi / python2 - works as expected:
Quote:03:16:50.027 T:140405785990912   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.AttributeError'>
                                            Error Contents: 'xbmcaddon.Addon' object has no attribute 'decode'
                                            Traceback (most recent call last):
                                              File "/home/ronie/.kodi/addons/script.test/default.py", line 3, in <module>
                                                path = xbmcaddon.Addon().decode("utf-8")
                                            AttributeError: 'xbmcaddon.Addon' object has no attribute 'decode'
                                            -->End of Python script error report<--

03:16:50.028 T:140405785990912    INFO: Python script stopped


kodi / python3 - nothing, no traceback:
Quote:03:15:56.100 T:140119403353856   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <class 'AttributeError'>
                                            Error Contents: 'xbmcaddon.Addon' object has no attribute 'decode'
                                            -->End of Python script error report<--
03:15:56.122 T:140119403353856    INFO: Python script stopped
Indeed, Kodi internally uses traceback module to retrieve human-readable traceback info for logging: https://github.com/xbmc/xbmc/blob/38f3bb...g.cpp#L168

But, as far as I can see, the code hasn't changed from Python 2 so maybe something has changed in how Python 3 handles exceptions internally. My educated guess is that exception info obtained by PyErr_Fetch() is not normalized as recommended in Python-C documentation: https://docs.python.org/3.6/c-api/except...eException. Normalization was required in Python 2 too, but it seems that in Python 3 PyErr_Fetch() returns unnormalized exceptions far more often if not always. 

I'll need to do some experiments and if my guess is correct I'll submit a PR.
The fix seems to be working:
Code:
19:36:41.259 T:6176 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <class 'AttributeError'>
Error Contents: 'str' object has no attribute 'decode'
Traceback (most recent call last):
File "D:\Kodi18_Py3\portable_data\addons\addon.tester\main.py", line 11, in <module>
path = addon.getAddonInfo('path').decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
-->End of Python script error report<--

@ronie Please try this build and test how it works.
thanx for looking in to it Roman_V_M !

if you can get me a diff or push the changes to your github repo, i'll compile and test it.
in other words... i'm not a windows user ;-)
(2018-02-08, 22:16)ronie Wrote: [ -> ]if you can get me a diff or push the changes to your github repo

Done. See this branch: https://github.com/romanvm/xbmc/tree/fix_py_traceback
thx! been using it for a few day now, and can confirm the issue is gone now.
Looking to develop my next add-on... I know it is going to take a while for me to complete. With that said is there a more stable version available yet for window last I tired a couple months ago this long / callback was a issue along with it randomly crashing.
(2018-04-02, 12:20)smitchell6879 Wrote: [ -> ]Looking to develop my next add-on... I know it is going to take a while for me to complete. With that said is there a more stable version available yet for window last I tired a couple months ago this long / callback was a issue along with it randomly crashing.
 http://mirrors.kodi.tv/test-builds/windows/win64/ the one with python3 is what you looking for