Fix excepthook for Python.

This commit is contained in:
Mikaël Capelle
2022-04-29 18:09:27 +02:00
parent 275acba6dd
commit 21aeebdcc8
2 changed files with 37 additions and 14 deletions
+24 -12
View File
@@ -4,58 +4,70 @@
<context>
<name>ProxyPython</name>
<message>
<location filename="proxypython.cpp" line="166"/>
<location filename="proxypython.cpp" line="121"/>
<source>Python Initialization failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="122"/>
<source>On a previous start the Python Plugin failed to initialize.
Do you want to try initializing python again (at the risk of another crash)?
Suggestion: Select &quot;no&quot;, and click the warning sign for further help.Afterwards you have to re-enable the python plugin.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="169"/>
<source>Python Proxy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="176"/>
<location filename="proxypython.cpp" line="179"/>
<source>Proxy Plugin to allow plugins written in python to be loaded</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="248"/>
<location filename="proxypython.cpp" line="251"/>
<source>ModOrganizer path contains a semicolon</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="250"/>
<location filename="proxypython.cpp" line="253"/>
<source>Python DLL not found</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="252"/>
<location filename="proxypython.cpp" line="255"/>
<source>Invalid Python DLL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="254"/>
<location filename="proxypython.cpp" line="257"/>
<source>Initializing Python failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="256"/>
<location filename="proxypython.cpp" line="286"/>
<location filename="proxypython.cpp" line="259"/>
<location filename="proxypython.cpp" line="289"/>
<source>invalid problem key %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="264"/>
<location filename="proxypython.cpp" line="267"/>
<source>The path to Mod Organizer (%1) contains a semicolon. &lt;br&gt;While this is legal on NTFS drives, many softwares do not handle it correctly.&lt;br&gt;Unfortunately MO depends on libraries that seem to fall into that group.&lt;br&gt;As a result the python plugin cannot be loaded, and the only solution we canoffer is to remove the semicolon or move MO to a path without a semicolon.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="275"/>
<location filename="proxypython.cpp" line="278"/>
<source>The Python plugin DLL was not found, maybe your antivirus deleted it. Re-installing MO2 might fix the problem.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="278"/>
<location filename="proxypython.cpp" line="281"/>
<source>The Python plugin DLL is invalid, maybe your antivirus is blocking it. Re-installing MO2 and adding exclusions for it to your AV might fix the problem.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxypython.cpp" line="283"/>
<location filename="proxypython.cpp" line="286"/>
<source>The initialization of the Python plugin DLL failed, unfortunately without any details.</source>
<translation type="unfinished"></translation>
</message>
+13 -2
View File
@@ -4,6 +4,7 @@
#include <set>
#include <sstream>
#include <pybind11/eval.h>
#include <pybind11/pybind11.h>
#include "log.h"
@@ -67,8 +68,18 @@ namespace mo2::python {
sys.attr("stdout") = printWrapper();
sys.attr("stderr") = errorWrapper();
// not sure if still needed for pybind11?
sys.attr("excepthook") = sys.attr("__excepthook__");
// this is required to handle exception in Python code OUTSIDE of pybind11 call,
// typically on Qt classes with methods overridden on the Python side
//
// without this, the application will crash instead of properly handling the
// exception as it would do with a py::error_already_set{}
//
// IMPORTANT: sys.attr("excepthook") = sys.attr("__excepthook__") DOES NOT WORK,
// and I have no clue why since the attribute does not seem to get updated (at
// least a print does not show it)
//
sys.attr("excepthook") =
py::eval("lambda x, y, z: sys.__excepthook__(x, y, z)");
}
// Small structure to hold the levels - There are copy paste from