]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestUtils.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / request / NodeRequestUtils.java
index 2e67010eba24bf013d9da01c884b3f7d174409b3..00eb2a492ffd4243329e8b0d2706a7d4535d0d68 100644 (file)
@@ -1,55 +1,58 @@
-package org.simantics.document.server.request;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.PrintStream;\r
-import java.io.UnsupportedEncodingException;\r
-\r
-import org.simantics.db.layer0.exception.MissingVariableException;\r
-import org.simantics.db.layer0.scl.SCLDatabaseException;\r
-import org.simantics.document.server.DocumentException;\r
-import org.simantics.scl.compiler.module.repository.ImportFailure;\r
-import org.simantics.scl.compiler.module.repository.ImportFailureException;\r
-import org.simantics.scl.compiler.top.NotFoundException;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NodeRequestUtils {\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(NodeRequestUtils.class);\r
-\r
-       public static String formatErrorMessage(String name, Throwable t) {\r
-               \r
-               while(t.getCause() != null)\r
-            t = t.getCause();\r
-               \r
-               if (t instanceof DocumentException) {\r
-                       return t.getMessage();\r
-               } else if (t instanceof MissingVariableException) {\r
-                       return "Evaluation of property '" + name + "' failed\n" +\r
-                                       t.getMessage();\r
-               } else if (t instanceof SCLDatabaseException) {\r
-                       return t.getMessage();\r
-               } else if (t instanceof NotFoundException) {\r
-                       return t.getMessage();\r
-               } else if (t instanceof ImportFailureException) {\r
-                       ImportFailureException e = (ImportFailureException)t;\r
-                       StringBuilder sb = new StringBuilder();\r
-                       sb.append("The following SCL modules failed to compile:\n");\r
-                       for(ImportFailure f : e.failures)\r
-                               sb.append(" " + f.moduleName + "\n");\r
-                       return sb.toString();\r
-               } else {\r
-                   LOGGER.error("Node request error:", t);\r
-                   \r
-                       ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
-                       PrintStream ps = new PrintStream(baos);\r
-                       t.printStackTrace(ps);\r
-                       try {\r
-                               return baos.toString("UTF-8");\r
-                       } catch (UnsupportedEncodingException e) {\r
-                               return baos.toString();\r
-                       }\r
-                       \r
-               }\r
-       }\r
-       \r
-}\r
+package org.simantics.document.server.request;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+
+import org.simantics.db.layer0.exception.MissingVariableException;
+import org.simantics.db.layer0.scl.SCLDatabaseException;
+import org.simantics.document.server.DocumentException;
+import org.simantics.scl.compiler.module.repository.ImportFailure;
+import org.simantics.scl.compiler.module.repository.ImportFailureException;
+import org.simantics.scl.compiler.top.NotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NodeRequestUtils {
+    private static final Logger LOGGER = LoggerFactory.getLogger(NodeRequestUtils.class);
+
+       public static String formatErrorMessage(String name, Throwable t) {
+               
+               while(t.getCause() != null)
+            t = t.getCause();
+               
+               if (t instanceof DocumentException) {
+                       return t.getMessage();
+               } else if (t instanceof MissingVariableException) {
+                       return name + ":\n" +
+                                       t.getMessage().replaceAll("(?m)^", "  ");
+               } else if (t instanceof SCLDatabaseException) {
+                       StringBuilder sb = new StringBuilder();
+                       sb.append(name + ":\n");
+                       sb.append(t.getMessage().replaceAll("(?m)^", "  "));
+                       return sb.toString();
+               } else if (t instanceof NotFoundException) {
+                       return t.getMessage();
+               } else if (t instanceof ImportFailureException) {
+                       ImportFailureException e = (ImportFailureException)t;
+                       StringBuilder sb = new StringBuilder();
+                       sb.append("The following SCL modules failed to compile:\n");
+                       for(ImportFailure f : e.failures)
+                               sb.append(" " + f.moduleName + "\n");
+                       return sb.toString();
+               } else {
+                   LOGGER.error("Node request error:", t);
+                   
+                       ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                       PrintStream ps = new PrintStream(baos);
+                       t.printStackTrace(ps);
+                       try {
+                               return baos.toString("UTF-8");
+                       } catch (UnsupportedEncodingException e) {
+                               return baos.toString();
+                       }
+                       
+               }
+       }
+       
+}