app, libgimpbase: do not try to open a non existing file.

Now that GimpParamSpecFile makes file validation depending on the action
set in the param spec, when trying to open a non-existing file (which
can happen through GUI, for instance when opening through the Document
History dockable or Open Recent menu), we had a quite obscure error
about a value "out of range" used "for argument 'file' (#2, type
GFile)", which is because core tried to set the GFile for a non-existing
file into the second parameter of the plug-in PDB. This is not a very
nice error for end-users.

The old error was much nicer as it used to say things like:

> Could not open '/path/not/existing.png' for reading: No such file or directory

But in fact, this string came from the plug-in, which means:

* first that the error can be different depending on the format
  (inconsistency of error message);
* depending on bugs in plug-ins, it may just crash or return no error
  messages;
* finally we were making a useless call to a load plug-in while we
  should already know from core that it won't work.

The new message is something like:

> Error when getting information for file "/path/not/existing.png: No such file or directory

This error is generated by core, so it will always be consistently the
same, is understandable too and the plug-in won't even be called.

As a side related fix, I updated the GimpParamSpecFile validation to
only validate local files, just like we do in core. Remote files can
always be set (and we let plug-ins handle them), at least for the time
being.
This commit is contained in:
Jehan 2025-01-23 17:50:05 +01:00
parent f9203916c0
commit 042d3051c6
2 changed files with 26 additions and 19 deletions

View file

@ -293,7 +293,7 @@ gimp_param_spec_file_validate (GParamSpec *pspec,
{
modifying = TRUE;
}
else if (file != NULL)
else if (file != NULL && g_file_is_native (file))
{
gboolean exists = g_file_query_exists (file, NULL);
GFileType type = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL);