1 package org.simantics.document.server.request;
\r
3 import java.io.ByteArrayOutputStream;
\r
4 import java.io.PrintStream;
\r
5 import java.io.UnsupportedEncodingException;
\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
15 public class NodeRequestUtils {
\r
17 public static String formatErrorMessage(String name, Throwable t) {
\r
19 while(t.getCause() != null)
\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
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
39 Logger.defaultLogError(t);
\r
41 ByteArrayOutputStream baos = new ByteArrayOutputStream();
\r
42 PrintStream ps = new PrintStream(baos);
\r
43 t.printStackTrace(ps);
\r
45 return baos.toString("UTF-8");
\r
46 } catch (UnsupportedEncodingException e) {
\r
47 return baos.toString();
\r