[Libosinfo] [libosinfo 4/6] Use OSINFO_ERROR in more places

Christophe Fergeau cfergeau at redhat.com
Thu Sep 20 13:59:20 UTC 2018


Passing a NULL error domain will trigger runtime warnings from glib.
---
 osinfo/osinfo_install_script.c | 37 ++++++++++++++++++++--------------
 tools/osinfo-install-script.c  |  2 +-
 tools/osinfo-query.c           |  6 +++---
 3 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
index 52b6d75f..a1d2373e 100644
--- a/osinfo/osinfo_install_script.c
+++ b/osinfo/osinfo_install_script.c
@@ -581,7 +581,7 @@ static xsltStylesheetPtr osinfo_install_script_load_template(const gchar *uri,
     /* Set up a parser context so we can catch the details of XML errors. */
     pctxt = xmlNewParserCtxt();
     if (!pctxt || !pctxt->sax) {
-        g_set_error(error, 0, 0, "%s",
+        g_set_error(error, OSINFO_ERROR, 0, "%s",
                     _("Unable to create XML parser context"));
         goto cleanup;
     }
@@ -589,13 +589,13 @@ static xsltStylesheetPtr osinfo_install_script_load_template(const gchar *uri,
     if (!(doc = xmlCtxtReadDoc(pctxt, BAD_CAST template, uri, NULL,
                                XML_PARSE_NOENT | XML_PARSE_NONET |
                                XML_PARSE_NOWARNING))) {
-        g_set_error(error, 0, 0, "%s",
+        g_set_error(error, OSINFO_ERROR, 0, "%s",
                     _("Unable to read XSL template"));
         goto cleanup;
     }
 
     if (!(xslt = xsltParseStylesheetDoc(doc))) {
-        g_set_error(error, 0, 0, "%s",
+        g_set_error(error, OSINFO_ERROR, 0, "%s",
                     _("Unable to parse XSL template"));
         goto cleanup;
     }
@@ -669,7 +669,8 @@ static xmlNodePtr osinfo_install_script_generate_entity_xml(OsinfoInstallScript
 
     if (!(node = xmlNewDocNode(NULL, NULL, (xmlChar*)name, NULL))) {
         xmlErrorPtr err = xmlGetLastError();
-        g_set_error(error, 0, 0, _("Unable to create XML node '%s': '%s'"),
+        g_set_error(error, OSINFO_ERROR, 0,
+                    _("Unable to create XML node '%s': '%s'"),
                     name, err ? err->message : "");
         goto error;
     }
@@ -677,13 +678,16 @@ static xmlNodePtr osinfo_install_script_generate_entity_xml(OsinfoInstallScript
     if (!(data = xmlNewDocRawNode(NULL, NULL, (const xmlChar*)"id",
                                   (const xmlChar*)osinfo_entity_get_id(entity)))) {
         xmlErrorPtr err = xmlGetLastError();
-        g_set_error(error, 0, 0, _("Unable to create XML node 'id': '%s'"),
+        g_set_error(error, OSINFO_ERROR, 0,
+                    _("Unable to create XML node 'id': '%s'"),
                     err ? err->message : "");
         goto error;
     }
     if (!(xmlAddChild(node, data))) {
         xmlErrorPtr err = xmlGetLastError();
-        g_set_error(error, 0, 0, _("Unable to add XML child '%s'"), err ? err->message : "");
+        g_set_error(error, OSINFO_ERROR, 0,
+                    _("Unable to add XML child '%s'"),
+                    err ? err->message : "");
         goto error;
     }
     data = NULL;
@@ -705,13 +709,16 @@ static xmlNodePtr osinfo_install_script_generate_entity_xml(OsinfoInstallScript
             if (!(data = xmlNewDocRawNode(NULL, NULL, (const xmlChar*)tmp1->data,
                                           (const xmlChar*)tmp2->data))) {
                 xmlErrorPtr err = xmlGetLastError();
-                g_set_error(error, 0, 0, _("Unable to create XML node '%s': '%s'"),
+                g_set_error(error, OSINFO_ERROR, 0,
+                            _("Unable to create XML node '%s': '%s'"),
                             (const gchar *)tmp1->data, err ? err->message : "");
                 goto error;
             }
             if (!(xmlAddChild(node, data))) {
                 xmlErrorPtr err = xmlGetLastError();
-                g_set_error(error, 0, 0, _("Unable to add XML child '%s'"), err ? err->message : "");
+                g_set_error(error, OSINFO_ERROR, 0,
+                            _("Unable to add XML child '%s'"),
+                            err ? err->message : "");
                 goto error;
             }
             data = NULL;
@@ -758,7 +765,7 @@ static xmlDocPtr osinfo_install_script_generate_config_xml(OsinfoInstallScript *
         goto error;
     if (!(xmlAddChild(root, node))) {
         xmlErrorPtr err = xmlGetLastError();
-        g_set_error(error, 0, 0, _("Unable to set XML root '%s'"), err ? err->message : "");
+        g_set_error(error, OSINFO_ERROR, 0, _("Unable to set XML root '%s'"), err ? err->message : "");
         goto error;
     }
 
@@ -769,7 +776,7 @@ static xmlDocPtr osinfo_install_script_generate_config_xml(OsinfoInstallScript *
         goto error;
     if (!(xmlAddChild(root, node))) {
         xmlErrorPtr err = xmlGetLastError();
-        g_set_error(error, 0, 0, _("Unable to set XML root '%s'"), err ? err->message : "");
+        g_set_error(error, OSINFO_ERROR, 0, _("Unable to set XML root '%s'"), err ? err->message : "");
         goto error;
     }
 
@@ -781,7 +788,7 @@ static xmlDocPtr osinfo_install_script_generate_config_xml(OsinfoInstallScript *
             goto error;
         if (!(xmlAddChild(root, node))) {
             xmlErrorPtr err = xmlGetLastError();
-            g_set_error(error, 0, 0, _("Unable to set 'media' node: '%s'"), err ? err->message : "");
+            g_set_error(error, OSINFO_ERROR, 0, _("Unable to set 'media' node: '%s'"), err ? err->message : "");
             goto error;
         }
     }
@@ -793,7 +800,7 @@ static xmlDocPtr osinfo_install_script_generate_config_xml(OsinfoInstallScript *
         goto error;
     if (!(xmlAddChild(root, node))) {
         xmlErrorPtr err = xmlGetLastError();
-        g_set_error(error, 0, 0, _("Unable to set XML root '%s'"), err ? err->message : "");
+        g_set_error(error, OSINFO_ERROR, 0, _("Unable to set XML root '%s'"), err ? err->message : "");
         goto error;
     }
 
@@ -816,17 +823,17 @@ static gchar *osinfo_install_script_apply_xslt(xsltStylesheetPtr ss,
     int len;
 
     if (!(ctxt = xsltNewTransformContext(ss, doc))) {
-        g_set_error(error, 0, 0, "%s", _("Unable to create XSL transform context"));
+        g_set_error(error, OSINFO_ERROR, 0, "%s", _("Unable to create XSL transform context"));
         goto cleanup;
     }
 
     if (!(docOut = xsltApplyStylesheetUser(ss, doc, NULL, NULL, NULL, ctxt))) {
-        g_set_error(error, 0, 0, "%s", _("Unable to apply XSL transform context"));
+        g_set_error(error, OSINFO_ERROR, 0, "%s", _("Unable to apply XSL transform context"));
         goto cleanup;
     }
 
     if (xsltSaveResultToString(&xsltResult, &len, docOut, ss) < 0) {
-        g_set_error(error, 0, 0, "%s", _("Unable to convert XSL output to string"));
+        g_set_error(error, OSINFO_ERROR, 0, "%s", _("Unable to convert XSL output to string"));
         goto cleanup;
     }
     ret = g_strdup((gchar *)xsltResult);
diff --git a/tools/osinfo-install-script.c b/tools/osinfo-install-script.c
index 35350225..36ad20fa 100644
--- a/tools/osinfo-install-script.c
+++ b/tools/osinfo-install-script.c
@@ -49,7 +49,7 @@ static gboolean handle_config(const gchar *option_name G_GNUC_UNUSED,
     gsize len;
 
     if (!(val = strchr(value, '='))) {
-        g_set_error(error, 0, 0,
+        g_set_error(error, OSINFO_ERROR, 0,
                     _("Expected configuration key=value"));
         return FALSE;
     }
diff --git a/tools/osinfo-query.c b/tools/osinfo-query.c
index 0a91bf06..aa318b85 100644
--- a/tools/osinfo-query.c
+++ b/tools/osinfo-query.c
@@ -149,7 +149,7 @@ static gboolean toggle_fields(struct OsinfoLabel *labels,
             }
         }
         if (!found) {
-            g_set_error(error, 0, 0,
+            g_set_error(error, OSINFO_ERROR, 0,
                         _("Unknown property name %s"), fields[i]);
             goto cleanup;
         }
@@ -174,7 +174,7 @@ static gboolean build_filter(struct OsinfoLabel *labels,
     for (i = 0; i < argc; i++) {
         const gchar *tmp = strchr(argv[i], '=');
         if (!tmp) {
-            g_set_error(error, 0, 0, "%s", _("Syntax error in condition, expecting KEY=VALUE"));
+            g_set_error(error, OSINFO_ERROR, 0, "%s", _("Syntax error in condition, expecting KEY=VALUE"));
             goto cleanup;
         }
         gchar *key = g_strndup(argv[i], tmp-argv[i]);
@@ -187,7 +187,7 @@ static gboolean build_filter(struct OsinfoLabel *labels,
         }
 
         if (!found) {
-            g_set_error(error, 0, 0,
+            g_set_error(error, OSINFO_ERROR, 0,
                         _("Unknown property name %s"), key);
             goto cleanup;
         }
-- 
2.19.0




More information about the Libosinfo mailing list