]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Improved exception information and logging in PlatformUtil.getGraph() 03/1003/4
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 20 Sep 2017 03:49:07 +0000 (06:49 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 20 Sep 2017 05:30:06 +0000 (08:30 +0300)
* Wrap all Exceptions that may occur during execution
* Log and rethrow any Errors thrown to be able to trace startup errors
  in case of malformed graph.tg inputs

refs #7496

Change-Id: I3cd46f68ba389935ffb795e1b4bfc081d9ee5e75

bundles/org.simantics.project/src/org/simantics/project/management/PlatformUtil.java

index d962ba090d9919cebc6b0f00a2bffefa5e06489e..d37947c4e2e11a5587e50e0e87b3b2a509937be5 100644 (file)
@@ -44,7 +44,6 @@ import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.databoard.container.DataContainer;
 import org.simantics.databoard.container.DataContainers;
 import org.simantics.databoard.serialization.SerializationException;
-import org.simantics.db.common.utils.Logger;
 import org.simantics.graph.compiler.CompilationResult;
 import org.simantics.graph.compiler.GraphCompiler;
 import org.simantics.graph.compiler.GraphCompilerPreferences;
@@ -54,6 +53,8 @@ import org.simantics.ltk.FileSource;
 import org.simantics.ltk.ISource;
 import org.simantics.ltk.Problem;
 import org.simantics.scl.reflection.OntologyVersions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This class contains utilities for managing bundles in a active platform. 
@@ -62,7 +63,8 @@ import org.simantics.scl.reflection.OntologyVersions;
 @SuppressWarnings("restriction")
 public class PlatformUtil {
 
-       
+       private static final Logger LOGGER = LoggerFactory.getLogger(PlatformUtil.class);
+
        /**
         * Get all bundles in the platform.
         * 
@@ -204,16 +206,16 @@ public class PlatformUtil {
                                File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
                                return path;
                        } catch (UnsupportedEncodingException e) {
-                               Logger.defaultLogError(e);
+                               LOGGER.error("Failed to decode " + url, e);
                        }
                } else if ("jar".equals(url.getProtocol())) {
                        try {
                                File libFile = extractLib(url, fileName);
                                return libFile;
                        } catch (FileNotFoundException e) {
-                               Logger.defaultLogError(e);
+                               LOGGER.error("Extraction to " + fileName + " failed, url not found: " + url, e);
                        } catch (IOException e) {
-                               Logger.defaultLogError(e);
+                               LOGGER.error("Extraction to " + fileName + " failed from url " + url, e);
                        }
                } else {
                        System.err.println("Unsupported URL protocol '" + url + "' for FastLZ native library file '" + fileName);
@@ -265,7 +267,7 @@ public class PlatformUtil {
                        errorStringBuilder.append(problem.getLocation() + ": " + problem.getDescription() + "\n");
 
                if(errorStringBuilder.length() > 0) {
-                       Logger.defaultLogError(errorStringBuilder.toString());
+                       LOGGER.error(errorStringBuilder.toString());
                } else {
                        DataContainers.writeFile(new File(bundleFile, "graph.tg"), 
                                        new DataContainer("graph", 1, new Variant(TransferableGraph1.BINDING, result.getGraph())));
@@ -296,7 +298,7 @@ public class PlatformUtil {
                                                }
                                        }
                                } catch (Throwable e) {
-                                       Logger.defaultLogError(e);
+                                       LOGGER.error("Failed to compile dynamic ontologies in bundle " + bundle.getSymbolicName(), e);
                                }
                        }
                }
@@ -370,24 +372,20 @@ public class PlatformUtil {
                        GraphBundleEx entry = new GraphBundleEx(name, graph, vid, isImmutable);
 //                     System.out.println("getGraph(" + bundle.getSymbolicName() + "): completed in " + (System.nanoTime()-start)*1e-6 + "ms");
                        return entry;
-               } catch (SerializationException e) {
-                       throw new IOException(e);
-               } catch (IOException e) {
-                       throw new IOException("Problem loading graph.tg from bundle " + bundle.getSymbolicName(), e);
-               } catch (RuntimeException e) {
-                       throw new IOException("Problem loading graph.tg from bundle " + bundle.getSymbolicName(), e);
-               } catch (AdaptException e) {
+               } catch (Exception e) {
                        throw new IOException("Problem loading graph.tg from bundle " + bundle.getSymbolicName(), e);
+               } catch (Error e) {
+                       LOGGER.error("Serious problem loading graph.tg from bundle " + bundle.getSymbolicName(), e);
+                       throw e;
                } finally {
                        is.close();
                }
        }
-       
+
        public static class TGInfo {
                public Bundle bundle;
                public URL location;
                public IVersionedId vid;
        }
-       
-}
 
+}
\ No newline at end of file