Error reports from libgsf



I've written some experiments into using libgsf to load files in
Conglomerate, but ran into problems.

The background is that I've got a set of error-handling routines in
Conglomerate which I'd like to eventually get moved into the platform
libraries.  They interpret error codes during File->Open and File->Save
operations and try to generate user-friendly, localised dialogs with
appropriate convenience buttons.

This means that I need to look at the GErrors that come from libgsf and
act accordingly.  Unfortunately, at the moment, the errors all use
gsf_input_error and gsf_output error for the domain, often with a code
of zero.

Attached is a patch to libgsf which attempts to provide more detailed
error information.  The idea is that each subclass of GsfInput and
GsfOutput gets a domain quark with its own string, and the error code is
given a domain-specific value.  For example GnomeVFS errors get
GnomeVFSResult codes.  

The patch is only a first draft at implementing this, and only supports
the subclasses I wanted to support.  Before I tidy up the patch, I
wanted to know: is this approach acceptable, or does it break existing
code somewhere?

In the long term I'd like the error domain strings and error code
semantics to be treated as a part of the ABI contract, so that my error
dialog library can depend on them.

Thoughts?

-- 
David Malcolm
www.conglomerate.org
? error-reporting.patch
? libgsf-zip
Index: gsf/gsf-input-stdio.c
===================================================================
RCS file: /cvs/gnome/libgsf/gsf/gsf-input-stdio.c,v
retrieving revision 1.24
diff -p -u -r1.24 gsf-input-stdio.c
--- gsf/gsf-input-stdio.c       24 Aug 2003 15:19:10 -0000      1.24
+++ gsf/gsf-input-stdio.c       24 Nov 2003 19:40:24 -0000
@@ -68,7 +68,7 @@ gsf_input_stdio_new (char const *filenam
        if (file == NULL || fstat (fileno (file), &st) < 0) {
                if (err != NULL) {
                        char *utf8name = gsf_filename_to_utf8 (filename, FALSE);
-                       *err = g_error_new (gsf_input_error (), 0,
+                       *err = g_error_new (gsf_input_stdio_error (), errno,
                                "%s: %s", utf8name, g_strerror (errno));
                        g_free (utf8name);
                }
@@ -79,7 +79,8 @@ gsf_input_stdio_new (char const *filenam
        if (!S_ISREG (st.st_mode)) {
                if (err != NULL) {
                        char *utf8name = gsf_filename_to_utf8 (filename, FALSE);
-                       *err = g_error_new (gsf_input_error (), 0,
+                       /* FIXME: need a better error code */
+                       *err = g_error_new (gsf_input_stdio_error (), EISDIR,
                                "%s: Is not a regular file", utf8name);
                        g_free (utf8name);
                }
@@ -96,6 +97,19 @@ gsf_input_stdio_new (char const *filenam
        gsf_input_set_name (GSF_INPUT (input), filename);
 
        return input;
+}
+
+/**
+ * gsf_input_stdio_error :
+ *
+ * Returns : A utility quark to flag a GError as being a GSF stdio input problem.
+ */
+GQuark gsf_input_stdio_error (void)
+{
+       static GQuark quark;
+       if (!quark)
+               quark = g_quark_from_static_string ("gsf_input_stdio_error");
+       return quark;
 }
 
 static void
Index: gsf/gsf-input-stdio.h
===================================================================
RCS file: /cvs/gnome/libgsf/gsf/gsf-input-stdio.h,v
retrieving revision 1.5
diff -p -u -r1.5 gsf-input-stdio.h
--- gsf/gsf-input-stdio.h       9 Mar 2003 18:15:34 -0000       1.5
+++ gsf/gsf-input-stdio.h       24 Nov 2003 19:40:24 -0000
@@ -34,6 +34,7 @@ typedef struct _GsfInputStdio GsfInputSt
 
 GType     gsf_input_stdio_get_type (void);
 GsfInputStdio *gsf_input_stdio_new      (char const *filename, GError **err);
+GQuark gsf_input_stdio_error (void);
 
 G_END_DECLS
 
Index: gsf-gnome/gsf-input-gnomevfs.c
===================================================================
RCS file: /cvs/gnome/libgsf/gsf-gnome/gsf-input-gnomevfs.c,v
retrieving revision 1.14
diff -p -u -r1.14 gsf-input-gnomevfs.c
--- gsf-gnome/gsf-input-gnomevfs.c      9 Mar 2003 18:15:36 -0000       1.14
+++ gsf-gnome/gsf-input-gnomevfs.c      24 Nov 2003 19:40:24 -0000
@@ -46,13 +46,14 @@ gsf_input_gnomevfs_setup_handle (GnomeVF
 
         res = gnome_vfs_get_file_info_from_handle (handle, &info, GNOME_VFS_FILE_INFO_DEFAULT);
         if (res != GNOME_VFS_OK) {
-            g_set_error (error, gsf_input_error (), (gint) res,
+            g_set_error (error, gsf_input_gnomevfs_error (), (gint) res,
                          gnome_vfs_result_to_string (res));
             return NULL;
         }        
         
         if (info.type != GNOME_VFS_FILE_TYPE_REGULAR) {
-            g_set_error (error, gsf_input_error (), 0,
+               /* FIXME:  is there a better Gnome VFS error code for this? */
+            g_set_error (error, gsf_input_gnomevfs_error (), (gint)GNOME_VFS_ERROR_IS_DIRECTORY,
                          "Not a regular file");
             gnome_vfs_close (handle);
             return NULL;
@@ -91,7 +92,7 @@ gsf_input_gnomevfs_new (char const *uri,
        res = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);       
 
        if (res != GNOME_VFS_OK) {
-               g_set_error (error, gsf_input_error (), (gint) res,
+               g_set_error (error, gsf_input_gnomevfs_error (), (gint) res,
                             gnome_vfs_result_to_string (res));
                return NULL;
        }
@@ -128,6 +129,20 @@ gsf_input_gnomevfs_new_uri (GnomeVFSURI 
 
        return input;
 }
+
+/**
+ * gsf_input_gnomevfs_error :
+ *
+ * Returns : A utility quark to flag a GError as being a GSF GnomeVFS input problem.
+ */
+GQuark gsf_input_gnomevfs_error (void)
+{
+       static GQuark quark;
+       if (!quark)
+               quark = g_quark_from_static_string ("gsf_input_gnomevfs_error");
+       return quark;
+}
+
 
 static void
 gsf_input_gnomevfs_finalize (GObject *obj)
Index: gsf-gnome/gsf-input-gnomevfs.h
===================================================================
RCS file: /cvs/gnome/libgsf/gsf-gnome/gsf-input-gnomevfs.h,v
retrieving revision 1.6
diff -p -u -r1.6 gsf-input-gnomevfs.h
--- gsf-gnome/gsf-input-gnomevfs.h      9 Mar 2003 18:15:36 -0000       1.6
+++ gsf-gnome/gsf-input-gnomevfs.h      24 Nov 2003 19:40:24 -0000
@@ -36,6 +36,7 @@ typedef struct _GsfInputGnomeVFS GsfInpu
 GType    gsf_input_gnomevfs_get_type (void);
 GsfInputGnomeVFS *gsf_input_gnomevfs_new      (char const *uri, GError **error);
 GsfInputGnomeVFS *gsf_input_gnomevfs_new_uri  (GnomeVFSURI *uri, GError **error);
+GQuark gsf_input_gnomevfs_error (void);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]