X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Frequest%2FNodeRequestUtils.java;fp=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Frequest%2FNodeRequestUtils.java;h=26f88608fb2e400fb34c46aad42002f03f4d8723;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestUtils.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestUtils.java new file mode 100644 index 000000000..26f88608f --- /dev/null +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestUtils.java @@ -0,0 +1,53 @@ +package org.simantics.document.server.request; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; + +import org.simantics.Logger; +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; + +public class NodeRequestUtils { + + 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 "Evaluation of property '" + name + "' failed\n" + + t.getMessage(); + } else if (t instanceof SCLDatabaseException) { + return t.getMessage(); + } 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.defaultLogError(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(); + } + + } + } + +}