Throw exception if compilation fails on server

This commit is contained in:
Andrey Breslav
2011-11-24 21:14:50 +03:00
parent aa007d415d
commit 1e63c6257c
3 changed files with 20 additions and 13 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -113,6 +114,7 @@ public class GenerationState {
} }
catch (Throwable e) { catch (Throwable e) {
errorHandler.reportException(e, namespace.getContainingFile().getVirtualFile().getUrl()); errorHandler.reportException(e, namespace.getContainingFile().getVirtualFile().getUrl());
DiagnosticUtils.throwIfRunningOnServer(e);
} }
} }
} }
@@ -11,6 +11,7 @@ import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.util.Function; import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.JetDeclaration; import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
@@ -68,18 +69,8 @@ public class AnalyzerFacade {
throw e; throw e;
} }
catch (Throwable e) { catch (Throwable e) {
// This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor. DiagnosticUtils.throwIfRunningOnServer(e);
if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true")) {
if (e instanceof RuntimeException) {
RuntimeException runtimeException = (RuntimeException) e;
throw runtimeException;
}
if (e instanceof Error) {
Error error = (Error) e;
throw error;
}
throw new RuntimeException(e);
}
e.printStackTrace(); e.printStackTrace();
BindingTraceContext bindingTraceContext = new BindingTraceContext(); BindingTraceContext bindingTraceContext = new BindingTraceContext();
bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e)); bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e));
@@ -93,5 +84,4 @@ public class AnalyzerFacade {
} }
return bindingContextCachedValue.getValue(); return bindingContextCachedValue.getValue();
} }
} }
@@ -81,4 +81,19 @@ public class DiagnosticUtils {
} }
return position; return position;
} }
public static void throwIfRunningOnServer(Throwable e) {
// This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor.
if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true")) {
if (e instanceof RuntimeException) {
RuntimeException runtimeException = (RuntimeException) e;
throw runtimeException;
}
if (e instanceof Error) {
Error error = (Error) e;
throw error;
}
throw new RuntimeException(e);
}
}
} }