plug-ins: python-fu-eval should correctly exit with error.

When the passed code had a bug, the plug-in was crashing along with the
code given in argument. Instead, we must catch all exceptions and pass
the error message raised by exec() to the core application.
This commit is contained in:
Jehan 2024-10-26 23:50:34 +02:00
parent 8cf1aaf40f
commit 97fb23e5b3

View file

@ -28,13 +28,23 @@ from gi.repository import GLib
from gi.repository import Gio
import sys
import traceback
def code_eval(procedure, run_mode, code, config, data):
retval = Gimp.PDBStatusType.SUCCESS
gerror = GLib.Error()
if code == '-':
code = sys.stdin.read()
try:
exec(code, globals())
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
except Exception as error:
retval = Gimp.PDBStatusType.CALLING_ERROR
gerror = GLib.Error(traceback.format_exc())
return procedure.new_return_values(retval, gerror)
class PythonEval (Gimp.PlugIn):
## GimpPlugIn virtual methods ##