After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 344818 - PDB procedures should give real error messages
PDB procedures should give real error messages
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: libgimp
git master
Other All
: High enhancement
: 2.6
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks: 101604 513291
 
 
Reported: 2006-06-13 21:41 UTC by Ari Pollak
Modified: 2008-08-20 18:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
untested patch, mainly for API review (18.98 KB, patch)
2008-08-12 22:40 UTC, Sven Neumann
none Details | Review
return error description as part of the return values (14.46 KB, patch)
2008-08-15 23:45 UTC, Sven Neumann
none Details | Review
full patch including changes to app/pdb (208.53 KB, patch)
2008-08-16 10:22 UTC, Sven Neumann
none Details | Review
next iteration of the patch including changes discussed on IRC (245.79 KB, patch)
2008-08-16 10:54 UTC, Sven Neumann
committed Details | Review
keep the error message in libgimp and provide a getter for it (4.00 KB, patch)
2008-08-16 15:35 UTC, Sven Neumann
none Details | Review
convert error message in procedure return values to a GError (8.86 KB, patch)
2008-08-16 19:24 UTC, Sven Neumann
committed Details | Review

Description Ari Pollak 2006-06-13 21:41:42 UTC
Originally http://bugs.debian.org/373184:

The current behavior of PDB is apparently to return only success or failure from a procedure, with no way to find out exactly what went wrong. This is a request to have more useful return values and/or error messages from procedures.
Comment 1 Sven Neumann 2006-06-19 10:22:22 UTC
Currently, when returning an error, PDB functions return just an error state. It would be possible to change this in a compatible way by optionally returning a string parameter that holds an error message. Callers would then have to check number and type of return arguments. If the first parameter is an error status, and a second string parameter exists, this would be taken as the error message.
Comment 2 Sven Neumann 2007-11-15 19:43:15 UTC
I am setting the 2.6 milestone on this one. Perhaps someone wants to address this. Otherwise we can always postpone it later...
Comment 3 Sven Neumann 2008-01-15 13:29:06 UTC
Changing version to "Current SVN" as this request is not specific to any particular version.

Note that some work on this feature has already been done in trunk. Errors in the core are now all handled using GError. What needs to be done is passing the error to the plug-in.
Comment 4 Sven Neumann 2008-02-12 12:51:29 UTC
We need an API proposal for this feature. As we don't want to break backwards compatibility, we must not change any of the existing PDB wrappers in libgimp. The current error handling (throwing up an error dialog) should also stay as the default behavior so that old plug-ins continue to behave as usual.
Comment 5 Sven Neumann 2008-02-12 13:06:51 UTC
Something like the following proposal could work.

First, the plug-in tells GIMP that it will handle PDB errors:

  gimp_procedural_db_set_error_handler (GIMP_PDB_ERROR_HANDLER_PLUG_IN);

Then, whenever it does a PDB call it would have to check the return value and in case the call fails, it retrieves the error:

  if (! gimp_image_flatten (image))
    {
       gchar *error = gimp_procedural_db_get_error ();

       // this is a stupid example,
       // of course the plug-in should do something more sensible
       gimp_message ("%s", error);
       g_free (error);
    }

Later it could reset the error handler to the default value:

  gimp_procedural_db_set_error_handler (GIMP_PDB_ERROR_HANDLER_GIMP);


Would this also work reasonably for scripts? Can someone think of a better API? Better function and/or enum names? Can this be implemented at all?
Comment 6 Michael Natterer 2008-02-12 13:47:54 UTC
This is just about what I had in mind too. The current error handler
and last error message would simply live in the GimpPlugInProcFrame
in the core, and I see no reason why this wouldn't work for plug-ins.
The Script-fu process would simply set the error handler just as
the temp_proc gets called and unset it before returning.

I wonder if the functions should be in message.psd or
plugin.pdb instead, The gimp_procedural_db_foo() functions
currently don't do any such "current plugin" stuff.
Comment 7 Sven Neumann 2008-02-12 14:01:31 UTC
You are right, it would be nicer to have an API with the gimp_plugin prefix for this. Can you think of good procedure names?
Comment 8 Michael Natterer 2008-02-12 14:04:50 UTC
I think i prefer gimp_message, since gimp_plugin currently only deals
with completely different stuff, while we already have another meessage
handler API in gimp_message.
Comment 9 Sven Neumann 2008-02-12 15:00:26 UTC
The procedures prefixed with gimp_message deal with message handling in the core while this API is about error handling in the context of procedures called from the plug-in. So I think this should be in the gimp_plugin prefix.
Comment 10 Martin Nordholts 2008-05-30 04:29:21 UTC
As far as I can see we see it is pretty clear how we want to solve this, so we're just waiting for someone to do it. Until someone does, let's keep this on the Future milestone.
Comment 11 Sven Neumann 2008-05-30 07:32:13 UTC
This is 90% implemented and it would be stupid not to finish the remaining bits for 2.6. We can still push it to 2.8 if we don't make it in time for the release.
Comment 12 Aaron Brick 2008-07-25 02:16:39 UTC
have needed this for years! looking forward to it!
Comment 13 Sven Neumann 2008-08-12 22:40:04 UTC
Created attachment 116460 [details] [review]
untested patch, mainly for API review
Comment 14 Sven Neumann 2008-08-15 23:45:10 UTC
Created attachment 116714 [details] [review]
return error description as part of the return values

Mitch and me figured that it would be better if the error message was pushed down to the caller as part of the procedure return values. This patch implements this. As before, the first return is always the status. But if it is GIMP_PDB_CALLING_ERROR, GIMP_PDB_EXECUTION_ERROR or GIMP_PDB_CANCEL, then the next return value can be string describing the cause of the failure.

The patch includes a small change to the Python bindings. With this patch the raised Exception includes the error message. This can be used to test the patch.
Comment 15 Sven Neumann 2008-08-16 10:22:23 UTC
Created attachment 116732 [details] [review]
full patch including changes to app/pdb
Comment 16 Sven Neumann 2008-08-16 10:54:29 UTC
Created attachment 116734 [details] [review]
next iteration of the patch including changes discussed on IRC
Comment 17 Sven Neumann 2008-08-16 13:58:14 UTC
2008-08-16  Sven Neumann  <sven@gimp.org>

	If a procedure call fails, pass a string describing the error as
	the second return value. First step towars fixing bug #344818.

	* app/pdb/gimpprocedure.[ch] (gimp_procedure_get_return_values):
	added a GError parameter. If it is set, pass the error message to
	the return values.

	* app/pdb/gimppdberror.h: added some more error codes.

	* app/pdb/gimppdb.c
	* app/xcf/xcf.c: pass errors to gimp_procedure_get_return_values().

	* app/plug-in/gimpplugin-message.c (gimp_plug_in_handle_proc_run):
	show a different error message for execution vs. calling errors.

	* app/plug-in/gimpplugin-progress.c
	(gimp_plug_in_progress_cancel_callback): pass the error
	GIMP_PDB_CANCELLED to gimp_procedure_get_return_values().

	* app/plug-in/gimppluginmanager-call.[ch]
	(gimp_plug_in_manager_call_run): removed the 'destroy_return_vals'
	parameter.

	* app/plug-in/gimppluginprocedure.c: destroy the return values here.

	* app/plug-in/gimppluginprocframe.c: pass an error to
	gimp_procedure_get_return_values().

	* tools/pdbgen/app.pl
	* tools/pdbgen/pdb/fileops.pdb: generate code that passes the
	error to gimp_procedure_get_return_values().

	* app/pdb/*-cmds.c: regenerated.
	
	* plug-ins/pygimp/pygimp-pdb.c: extract the error message from the
	return values and pass it to the exception that is thrown.
Comment 18 Sven Neumann 2008-08-16 15:35:12 UTC
Created attachment 116748 [details] [review]
keep the error message in libgimp and provide a getter for it
Comment 19 Sven Neumann 2008-08-16 17:19:07 UTC
I've committed something similar now:

2008-08-16  Sven Neumann  <sven@gimp.org>

	Next step towards fixing bug #344818:

	* libgimp/gimp.[ch]: keep the last error status and error message
	in libgimp. Added new functon gimp_pdb_get_error() that allows to
	retrieve it.

	* libgimp/gimp.def: updated.

	* plug-ins/pygimp/gimpmodule.c (pygimp_vectors_import_from_file)
	(pygimp_vectors_import_from_string): use the new function to get
	a more useful error message.
Comment 20 Sven Neumann 2008-08-16 19:24:57 UTC
Created attachment 116759 [details] [review]
convert error message in procedure return values to a GError

This patch takes care of converting error messages in procedure return values to a GError. It also changes the file-png plug-in to push error messages to the return values instead of using g_message(). You can test this by attempting to save a PNG file to a folder where you don't have write permissions.
Comment 21 Sven Neumann 2008-08-17 12:15:38 UTC
I've committed this patch (with some minor changes) to trunk:

2008-08-17  Sven Neumann  <sven@gimp.org>

	Next step towards fixing bug #344818:

	* app/pdb/gimpprocedure.c (gimp_procedure_execute): if the error
	has not already been set, construct one from the error message
	that is optionally passed with the return values.

	* plug-ins/common/file-png.c: changed to pass an error message
	with the return values instead of calling g_message() in case of
	an error.

We should review the changes in the file-png plug-in to see if this can be done easier before we apply this to all (file) plug-ins.
Comment 22 Sven Neumann 2008-08-18 22:56:58 UTC
2008-08-19  Sven Neumann  <sven@gimp.org>

	Complements the fix for bug #344818:

	* libgimpbase/gimpbaseenums.[ch]: added new enum GimpPDBErrorHandler.

	* tools/pdbgen/enums.pl: regenerated.

	* app/plug-in/gimpplugin.[ch]: added error_handler to GimpPlugIn.

	* app/plug-in/gimpplugin-message.c (gimp_plug_in_handle_proc_run):
	only display an error message for a failed procedure call if the
	plug-in's error-handler is set to GIMP_PDB_ERROR_HANDLER_INTERNAL.
	
	* tools/pdbgen/pdb/plug_in.pdb: added PDB getter and setter for
	the plug-in's error-handler.

	* app/pdb/plug-in-cmds.c
	* app/pdb/internal-procs.c
	* libgimp/gimpenums.c.tail
	* libgimp/gimpplugin_pdb.[ch]: regenerated.

	* plug-ins/common/file-compressor.c
	* plug-ins/file-uri/uri.c: set the error-handler to
	GIMP_PDB_ERROR_HANDLER_PLUGIN as these plug-ins are forwarding the
	error with their return values.


A few file plug-ins still need to be touched before this bug can be closed.

Overall there are certainly a lot more places where error handling could be improved. But since we don't want to introduce lots of string changes at this point, we should be careful. We can continue this crusade after 2.6.
Comment 23 Sven Neumann 2008-08-20 18:02:12 UTC
All file plug-ins touched, and a few other plug-ins as well. Closing as FIXED.