[PATCH db-tools 06/11] Set a valid error domain for GError

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

 



GLib will print a warning if 0 is passed for the GQuark
error domain when setting a GError. Define a valid error
domain quark and use it.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tools/osinfo-db-util.c     |  7 ++++++-
 tools/osinfo-db-util.h     |  3 +++
 tools/osinfo-db-validate.c | 14 +++++++-------
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/tools/osinfo-db-util.c b/tools/osinfo-db-util.c
index bd4a813..34abe88 100644
--- a/tools/osinfo-db-util.c
+++ b/tools/osinfo-db-util.c
@@ -27,6 +27,11 @@
 
 #include "osinfo-db-util.h"
 
+GQuark osinfo_db_error_quark(void)
+{
+    return g_quark_from_static_string("osinfo-db-error");
+}
+
 GFile *osinfo_db_get_system_path(const gchar *root)
 {
     GFile *file;
@@ -141,7 +146,7 @@ GFile *osinfo_db_get_file(const char *root,
     }
 
     if (!ret) {
-        g_set_error(err, 0, 0,
+        g_set_error(err, OSINFO_DB_ERROR, 0,
                     _("Unable to locate '%s' in any database location"),
                     file);
         return NULL;
diff --git a/tools/osinfo-db-util.h b/tools/osinfo-db-util.h
index d56c098..59ceadc 100644
--- a/tools/osinfo-db-util.h
+++ b/tools/osinfo-db-util.h
@@ -26,6 +26,9 @@
 
 #include <gio/gio.h>
 
+#define OSINFO_DB_ERROR osinfo_db_error_quark()
+
+GQuark osinfo_db_error_quark(void);
 GFile *osinfo_db_get_system_path(const gchar *root);
 GFile *osinfo_db_get_local_path(const gchar *root);
 GFile *osinfo_db_get_user_path(const gchar *root);
diff --git a/tools/osinfo-db-validate.c b/tools/osinfo-db-validate.c
index 2989f2e..ce3366a 100644
--- a/tools/osinfo-db-validate.c
+++ b/tools/osinfo-db-validate.c
@@ -58,7 +58,7 @@ static xmlDocPtr parse_file(GFile *file, GError **error)
         goto cleanup;
 
     if (!(pctxt = xmlNewParserCtxt())) {
-        g_set_error(error, 0, 0, "%s",
+        g_set_error(error, OSINFO_DB_ERROR, 0, "%s",
                     _("Unable to create libxml parser"));
         goto cleanup;
     }
@@ -66,7 +66,7 @@ static xmlDocPtr parse_file(GFile *file, GError **error)
     if (!(doc = xmlCtxtReadDoc(pctxt, (const xmlChar*)data, uri, NULL,
                                XML_PARSE_NOENT | XML_PARSE_NONET |
                                XML_PARSE_NOWARNING))) {
-        g_set_error(error, 0, 0,
+        g_set_error(error, OSINFO_DB_ERROR, 0,
                     _("Unable to parse XML document '%s'"),
                     uri);
         goto cleanup;
@@ -98,7 +98,7 @@ static gboolean validate_file_regular(xmlRelaxNGValidCtxtPtr rngValid,
         goto cleanup;
 
     if (xmlRelaxNGValidateDoc(rngValid, doc) != 0) {
-        g_set_error(error, 0, 0,
+        g_set_error(error, OSINFO_DB_ERROR, 0,
                     _("Unable to validate XML document '%s'"),
                     uri);
         goto cleanup;
@@ -166,7 +166,7 @@ static gboolean validate_file(xmlRelaxNGValidCtxtPtr rngValid, GFile *file, GFil
         if (!validate_file_regular(rngValid, file, error))
             goto cleanup;
     } else {
-        g_set_error(error, 0, 0,
+        g_set_error(error, OSINFO_DB_ERROR, 0,
                     "Unable to handle file type for %s",
                     uri);
         goto cleanup;
@@ -198,7 +198,7 @@ static gboolean validate_files(GFile *schema, gsize nfiles, GFile **files, GErro
     schemapath = g_file_get_path(schema);
     rngParser = xmlRelaxNGNewParserCtxt(schemapath);
     if (!rngParser) {
-        g_set_error(error, 0, 0,
+        g_set_error(error, OSINFO_DB_ERROR, 0,
                     _("Unable to create RNG parser for %s"),
                     schemapath);
         goto cleanup;
@@ -206,7 +206,7 @@ static gboolean validate_files(GFile *schema, gsize nfiles, GFile **files, GErro
 
     rng = xmlRelaxNGParse(rngParser);
     if (!rng) {
-        g_set_error(error, 0, 0,
+        g_set_error(error, OSINFO_DB_ERROR, 0,
                     _("Unable to parse RNG %s"),
                     schemapath);
         goto cleanup;
@@ -214,7 +214,7 @@ static gboolean validate_files(GFile *schema, gsize nfiles, GFile **files, GErro
 
     rngValid = xmlRelaxNGNewValidCtxt(rng);
     if (!rngValid) {
-        g_set_error(error, 0, 0,
+        g_set_error(error, OSINFO_DB_ERROR, 0,
                     _("Unable to create RNG validation context %s"),
                     schemapath);
         goto cleanup;
-- 
2.7.4

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux