From 7365cb8e52173a02d0ce0991036794840320b3ec Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sun, 5 Aug 2018 11:28:57 +0200 Subject: [PATCH] Get Exception handling working with Python 3 The old way to get the full stacktrace was incorrect, and does not work with Python 3: https://stackoverflow.com/questions/3702675/how-to-print-the-full-traceback-without-halting-the-program#comment84297600_33723119 --- pcbnew/swig/python_scripting.cpp | 8 ++++++++ scripting/kicadplugins.i | 6 ++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pcbnew/swig/python_scripting.cpp b/pcbnew/swig/python_scripting.cpp index 0f98bdcd44..d59f4a5554 100644 --- a/pcbnew/swig/python_scripting.cpp +++ b/pcbnew/swig/python_scripting.cpp @@ -447,7 +447,15 @@ wxString PyErrStringWithTraceback() PyErr_Fetch( &type, &value, &traceback ); + PyErr_NormalizeException( &type, &value, &traceback); + if (traceback == NULL) { + traceback = Py_None; + Py_INCREF( traceback ); + } + #if PY_MAJOR_VERSION >= 3 + PyException_SetTraceback(value, traceback); + PyObject* tracebackModuleString = PyUnicode_FromString( "traceback" ); #else PyObject* tracebackModuleString = PyString_FromString( "traceback" ); diff --git a/scripting/kicadplugins.i b/scripting/kicadplugins.i index a7550ebf91..b828327ee4 100644 --- a/scripting/kicadplugins.i +++ b/scripting/kicadplugins.i @@ -121,8 +121,7 @@ def LoadOnePlugin(Dirname, ModuleName): if NOT_LOADED_WIZARDS != "" : NOT_LOADED_WIZARDS += "\n" NOT_LOADED_WIZARDS += module_filename - FULL_BACK_TRACE += traceback.format_exc(sys.exc_info()) - pass + FULL_BACK_TRACE += traceback.format_exc() @@ -154,8 +153,7 @@ def LoadOneSubdirPlugin(Dirname, SubDirname): if NOT_LOADED_WIZARDS != "" : NOT_LOADED_WIZARDS += "\n" NOT_LOADED_WIZARDS += fullPath - FULL_BACK_TRACE += traceback.format_exc(sys.exc_info()) - pass + FULL_BACK_TRACE += traceback.format_exc() else: if NOT_LOADED_WIZARDS != "" :