From 445a60c9348c3cf0184d0d737232aaeb23bda587 Mon Sep 17 00:00:00 2001
From: Heinrichs <Heinrichs@itc.rwth-aachen.de>
Date: Fri, 4 Nov 2022 13:56:22 +0100
Subject: [PATCH] Fix: Catch and Print Virtuoso Errors

---
 src/SQL2Linked/StructuralData.cs | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/SQL2Linked/StructuralData.cs b/src/SQL2Linked/StructuralData.cs
index 53c7a0c..11df7b5 100644
--- a/src/SQL2Linked/StructuralData.cs
+++ b/src/SQL2Linked/StructuralData.cs
@@ -48,20 +48,30 @@ namespace SQL2Linked
         {
             foreach (var graph in graphs)
             {
-                Console.WriteLine($" ({graph.BaseUri})");
-                var exists = WrapRequest(() => RdfStoreConnector.HasGraph(graph.BaseUri));
-                if (exists)
+                try
                 {
-                    Console.WriteLine($" - Graph {graph.BaseUri} exists");
+                    Console.WriteLine($" ({graph.BaseUri})");
+                    var exists = WrapRequest(() => RdfStoreConnector.HasGraph(graph.BaseUri));
+                    if (exists)
+                    {
+                        Console.WriteLine($" - Graph {graph.BaseUri} exists");
 
-                    // Clear the existing graph from the store
-                    WrapRequest(() => RdfStoreConnector.ClearGraph(graph.BaseUri));
-                    Console.WriteLine($" - Cleared Graph {graph.BaseUri}");
+                        // Clear the existing graph from the store
+                        WrapRequest(() => RdfStoreConnector.ClearGraph(graph.BaseUri));
+                        Console.WriteLine($" - Cleared Graph {graph.BaseUri}");
+                    }
+                    // Add the new graph to the store
+                    WrapRequest(() => RdfStoreConnector.AddGraph(graph));
+                    Console.WriteLine($" - Graph {graph.BaseUri} added successfully");
+                    Console.WriteLine();
+                } 
+                catch (Exception e)
+                {
+                    Console.Error.WriteLine($"Error on ({graph.BaseUri}):");
+                    Console.Error.WriteLine(e);
+                    Console.Error.WriteLine(e.InnerException);
+                    Console.Error.WriteLine();
                 }
-                // Add the new graph to the store
-                WrapRequest(() => RdfStoreConnector.AddGraph(graph));
-                Console.WriteLine($" - Graph {graph.BaseUri} added successfully");
-                Console.WriteLine();
             }
         }
 
-- 
GitLab