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:
@ -28,13 +28,23 @@ from gi.repository import GLib
|
|||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
def code_eval(procedure, run_mode, code, config, data):
|
def code_eval(procedure, run_mode, code, config, data):
|
||||||
|
retval = Gimp.PDBStatusType.SUCCESS
|
||||||
|
gerror = GLib.Error()
|
||||||
|
|
||||||
if code == '-':
|
if code == '-':
|
||||||
code = sys.stdin.read()
|
code = sys.stdin.read()
|
||||||
exec(code, globals())
|
|
||||||
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
|
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):
|
class PythonEval (Gimp.PlugIn):
|
||||||
## GimpPlugIn virtual methods ##
|
## GimpPlugIn virtual methods ##
|
||||||
|
Reference in New Issue
Block a user