]> gerrit.simantics Code Review - simantics/platform.git/blob
26f88608fb2e400fb34c46aad42002f03f4d8723
[simantics/platform.git] /
1 package org.simantics.document.server.request;\r
2 \r
3 import java.io.ByteArrayOutputStream;\r
4 import java.io.PrintStream;\r
5 import java.io.UnsupportedEncodingException;\r
6 \r
7 import org.simantics.Logger;\r
8 import org.simantics.db.layer0.exception.MissingVariableException;\r
9 import org.simantics.db.layer0.scl.SCLDatabaseException;\r
10 import org.simantics.document.server.DocumentException;\r
11 import org.simantics.scl.compiler.module.repository.ImportFailure;\r
12 import org.simantics.scl.compiler.module.repository.ImportFailureException;\r
13 import org.simantics.scl.compiler.top.NotFoundException;\r
14 \r
15 public class NodeRequestUtils {\r
16 \r
17         public static String formatErrorMessage(String name, Throwable t) {\r
18                 \r
19                 while(t.getCause() != null)\r
20             t = t.getCause();\r
21                 \r
22                 if (t instanceof DocumentException) {\r
23                         return t.getMessage();\r
24                 } else if (t instanceof MissingVariableException) {\r
25                         return "Evaluation of property '" + name + "' failed\n" +\r
26                                         t.getMessage();\r
27                 } else if (t instanceof SCLDatabaseException) {\r
28                         return t.getMessage();\r
29                 } else if (t instanceof NotFoundException) {\r
30                         return t.getMessage();\r
31                 } else if (t instanceof ImportFailureException) {\r
32                         ImportFailureException e = (ImportFailureException)t;\r
33                         StringBuilder sb = new StringBuilder();\r
34                         sb.append("The following SCL modules failed to compile:\n");\r
35                         for(ImportFailure f : e.failures)\r
36                                 sb.append(" " + f.moduleName + "\n");\r
37                         return sb.toString();\r
38                 } else {\r
39                         Logger.defaultLogError(t);\r
40                         \r
41                         ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
42                         PrintStream ps = new PrintStream(baos);\r
43                         t.printStackTrace(ps);\r
44                         try {\r
45                                 return baos.toString("UTF-8");\r
46                         } catch (UnsupportedEncodingException e) {\r
47                                 return baos.toString();\r
48                         }\r
49                         \r
50                 }\r
51         }\r
52         \r
53 }\r