From 97fb23e5b3a7330ab805b14a5c8ec1c4cac0934c Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 26 Oct 2024 23:50:34 +0200 Subject: [PATCH] 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. --- plug-ins/python/python-eval.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plug-ins/python/python-eval.py b/plug-ins/python/python-eval.py index 4c863a684c..ef12c79a75 100644 --- a/plug-ins/python/python-eval.py +++ b/plug-ins/python/python-eval.py @@ -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() - exec(code, globals()) - return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error()) + code = sys.stdin.read() + + try: + exec(code, globals()) + 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 ##