[tracker/sam/ontology-docs: 22/25] docs/tools/ttl2xml: Return failed status on parse errors
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sam/ontology-docs: 22/25] docs/tools/ttl2xml: Return failed status on parse errors
- Date: Fri, 17 Apr 2020 00:48:52 +0000 (UTC)
commit cfbb766c66334d873084cc98e343fccdd1720f68
Author: Sam Thursfield <sam afuera me uk>
Date: Thu Apr 16 23:37:00 2020 +0200
docs/tools/ttl2xml: Return failed status on parse errors
Previously the tool would log parse errors but wouldn't fail, which
might lead to mistakes being missed.
docs/tools/ttl2xml.c | 12 ++++++++++--
docs/tools/ttl_loader.c | 23 +++++++++++++----------
docs/tools/ttl_loader.h | 5 +++--
3 files changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/docs/tools/ttl2xml.c b/docs/tools/ttl2xml.c
index 3089aa1a8..7129c1770 100644
--- a/docs/tools/ttl2xml.c
+++ b/docs/tools/ttl2xml.c
@@ -108,6 +108,8 @@ main (gint argc, gchar **argv)
GList *description_files, *l;
g_autoptr(GFile) ontology_file = NULL, output_file = NULL;
gchar *path;
+ gboolean success;
+ g_autoptr(GError) error = NULL;
/* Translators: this messagge will apper immediately after the */
/* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */
@@ -145,6 +147,7 @@ main (gint argc, gchar **argv)
g_mkdir_with_parents (path, 0755);
g_free (path);
+ success = TRUE;
for (l = description_files; l; l = l->next) {
Ontology *ontology = NULL;
g_autoptr(GFile) ttl_file = NULL, ttl_output_file = NULL;
@@ -159,7 +162,12 @@ main (gint argc, gchar **argv)
ontology = ttl_loader_new_ontology ();
- ttl_loader_load_ontology (ontology, ttl_file);
+ success &= ttl_loader_load_ontology (ontology, ttl_file, &error);
+
+ if (error) {
+ g_printerr ("%s: Turtle parse error: %s\n", g_file_peek_path (ttl_file),
error->message);
+ g_clear_error (&error);
+ }
ttl_xml_print (description, ontology, ttl_output_file, description_dir);
@@ -170,5 +178,5 @@ main (gint argc, gchar **argv)
g_option_context_free (context);
- return 0;
+ return !(success);
}
diff --git a/docs/tools/ttl_loader.c b/docs/tools/ttl_loader.c
index 103f04e26..54486bfe4 100644
--- a/docs/tools/ttl_loader.c
+++ b/docs/tools/ttl_loader.c
@@ -351,24 +351,25 @@ ttl_loader_new_ontology (void)
return ontology;
}
-void
+gboolean
ttl_loader_load_ontology (Ontology *ontology,
- GFile *ttl_file)
+ GFile *ttl_file,
+ GError **error)
{
TrackerTurtleReader *reader;
const gchar *subject, *predicate, *object;
const gchar *base_url, *prefix;
GHashTableIter iter;
- GError *error = NULL;
+ GError *inner_error = NULL;
- g_return_if_fail (G_IS_FILE (ttl_file));
+ g_return_val_if_fail (G_IS_FILE (ttl_file), 0);
- reader = tracker_turtle_reader_new_for_file (ttl_file, &error);
+ reader = tracker_turtle_reader_new_for_file (ttl_file, &inner_error);
- while (error == NULL &&
+ while (inner_error == NULL &&
tracker_turtle_reader_next (reader,
&subject, &predicate, &object,
- NULL, &error)) {
+ NULL, &inner_error)) {
load_in_memory (ontology, subject, predicate, object);
}
@@ -385,9 +386,11 @@ ttl_loader_load_ontology (Ontology *ontology,
g_clear_object (&reader);
- if (error) {
- g_message ("Turtle parse error: %s", error->message);
- g_error_free (error);
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return FALSE;
+ } else {
+ return TRUE;
}
}
diff --git a/docs/tools/ttl_loader.h b/docs/tools/ttl_loader.h
index 1f4fc50c3..b70bd33b4 100644
--- a/docs/tools/ttl_loader.h
+++ b/docs/tools/ttl_loader.h
@@ -28,8 +28,9 @@ G_BEGIN_DECLS
Ontology * ttl_loader_new_ontology (void);
-void ttl_loader_load_ontology (Ontology *ontology,
- GFile *filename);
+gboolean ttl_loader_load_ontology (Ontology *ontology,
+ GFile *filename,
+ GError **error);
OntologyDescription * ttl_loader_load_description (GFile *filename);
void ttl_loader_load_prefix_from_description (Ontology *ontology,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]