Report error in JPS when TeaVM build crashes

This commit is contained in:
Alexey Andreev 2017-06-06 23:08:31 +03:00
parent ba7f07de4b
commit 91a7f69bee
7 changed files with 68 additions and 6 deletions

View File

@ -24,6 +24,8 @@ public interface TeaVMBuildResult {
boolean isErrorOccurred(); boolean isErrorOccurred();
String getStackTrace();
ProblemProvider getProblems(); ProblemProvider getProblems();
Collection<String> getUsedResources(); Collection<String> getUsedResources();

View File

@ -31,4 +31,5 @@ public class TeaVMRemoteBuildResponse implements Serializable {
public final Set<String> usedResources = new HashSet<>(); public final Set<String> usedResources = new HashSet<>();
public final Set<String> classes = new HashSet<>(); public final Set<String> classes = new HashSet<>();
public final Set<String> generatedFiles = new HashSet<>(); public final Set<String> generatedFiles = new HashSet<>();
public String stackTrace;
} }

View File

@ -0,0 +1,32 @@
/*
* Copyright 2017 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.idea.jps.util;
import java.io.PrintWriter;
import java.io.StringWriter;
public final class ExceptionUtil {
private ExceptionUtil() {
}
public static String exceptionToString(Throwable e) {
StringWriter writer = new StringWriter();
PrintWriter output = new PrintWriter(writer);
e.printStackTrace(output);
output.close();
return writer.toString();
}
}

View File

@ -29,6 +29,7 @@ import org.teavm.callgraph.CallGraph;
import org.teavm.diagnostics.ProblemProvider; import org.teavm.diagnostics.ProblemProvider;
import org.teavm.idea.jps.model.TeaVMBuildResult; import org.teavm.idea.jps.model.TeaVMBuildResult;
import org.teavm.idea.jps.model.TeaVMBuildStrategy; import org.teavm.idea.jps.model.TeaVMBuildStrategy;
import org.teavm.idea.jps.util.ExceptionUtil;
import org.teavm.tooling.EmptyTeaVMToolLog; import org.teavm.tooling.EmptyTeaVMToolLog;
import org.teavm.tooling.TeaVMTargetType; import org.teavm.tooling.TeaVMTargetType;
import org.teavm.tooling.TeaVMTool; import org.teavm.tooling.TeaVMTool;
@ -135,10 +136,12 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy {
} }
boolean errorOccurred = false; boolean errorOccurred = false;
String stackTrace = null;
try { try {
tool.generate(); tool.generate();
} catch (TeaVMToolException | RuntimeException | Error e) { } catch (TeaVMToolException | RuntimeException | Error e) {
e.printStackTrace(System.err); e.printStackTrace(System.err);
stackTrace = ExceptionUtil.exceptionToString(e);
context.processMessage(new CompilerMessage("TeaVM", e)); context.processMessage(new CompilerMessage("TeaVM", e));
errorOccurred = true; errorOccurred = true;
} }
@ -147,7 +150,7 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy {
.map(File::getAbsolutePath) .map(File::getAbsolutePath)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
return new InProcessBuildResult(tool.getDependencyInfo().getCallGraph(), errorOccurred, return new InProcessBuildResult(tool.getDependencyInfo().getCallGraph(), errorOccurred, stackTrace,
tool.getProblemProvider(), tool.getClasses(), tool.getUsedResources(), generatedFiles); tool.getProblemProvider(), tool.getClasses(), tool.getUsedResources(), generatedFiles);
} }
@ -168,15 +171,18 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy {
static class InProcessBuildResult implements TeaVMBuildResult { static class InProcessBuildResult implements TeaVMBuildResult {
private CallGraph callGraph; private CallGraph callGraph;
private boolean errorOccurred; private boolean errorOccurred;
private String stackTrace;
private ProblemProvider problemProvider; private ProblemProvider problemProvider;
private Collection<String> classes; private Collection<String> classes;
private Collection<String> usedResources; private Collection<String> usedResources;
private Collection<String> generatedFiles; private Collection<String> generatedFiles;
InProcessBuildResult(CallGraph callGraph, boolean errorOccurred, ProblemProvider problemProvider, InProcessBuildResult(CallGraph callGraph, boolean errorOccurred, String stackTrace,
Collection<String> classes, Collection<String> usedResources, Collection<String> generatedFiles) { ProblemProvider problemProvider, Collection<String> classes, Collection<String> usedResources,
Collection<String> generatedFiles) {
this.callGraph = callGraph; this.callGraph = callGraph;
this.errorOccurred = errorOccurred; this.errorOccurred = errorOccurred;
this.stackTrace = stackTrace;
this.problemProvider = problemProvider; this.problemProvider = problemProvider;
this.classes = classes; this.classes = classes;
this.usedResources = usedResources; this.usedResources = usedResources;
@ -193,6 +199,11 @@ public class InProcessBuildStrategy implements TeaVMBuildStrategy {
return errorOccurred; return errorOccurred;
} }
@Override
public String getStackTrace() {
return stackTrace;
}
@Override @Override
public ProblemProvider getProblems() { public ProblemProvider getProblems() {
return problemProvider; return problemProvider;

View File

@ -133,6 +133,11 @@ public class RemoteBuildStrategy implements TeaVMBuildStrategy {
return response.errorOccurred; return response.errorOccurred;
} }
@Override
public String getStackTrace() {
return response.stackTrace;
}
@Override @Override
public ProblemProvider getProblems() { public ProblemProvider getProblems() {
return problems; return problems;

View File

@ -122,8 +122,16 @@ class TeaVMBuild {
reportProblems(buildResult.getProblems(), buildResult.getCallGraph()); reportProblems(buildResult.getProblems(), buildResult.getCallGraph());
for (String fileName : buildResult.getGeneratedFiles()) { if (!buildResult.isErrorOccurred()) {
outputConsumer.registerOutputFile(new File(fileName), Collections.emptyList()); for (String fileName : buildResult.getGeneratedFiles()) {
outputConsumer.registerOutputFile(new File(fileName), Collections.emptyList());
}
}
if (buildResult.getStackTrace() != null) {
context.processMessage(new CompilerMessage("TeaVM", BuildMessage.Kind.ERROR,
"Compiler crashed:\n" + buildResult.getStackTrace(), "",
-1, -1, -1, -1, -1));
} }
return true; return true;

View File

@ -47,6 +47,7 @@ import org.teavm.idea.jps.remote.TeaVMRemoteBuildCallback;
import org.teavm.idea.jps.remote.TeaVMRemoteBuildRequest; import org.teavm.idea.jps.remote.TeaVMRemoteBuildRequest;
import org.teavm.idea.jps.remote.TeaVMRemoteBuildResponse; import org.teavm.idea.jps.remote.TeaVMRemoteBuildResponse;
import org.teavm.idea.jps.remote.TeaVMRemoteBuildService; import org.teavm.idea.jps.remote.TeaVMRemoteBuildService;
import org.teavm.idea.jps.util.ExceptionUtil;
import org.teavm.tooling.EmptyTeaVMToolLog; import org.teavm.tooling.EmptyTeaVMToolLog;
import org.teavm.tooling.TeaVMTool; import org.teavm.tooling.TeaVMTool;
import org.teavm.tooling.TeaVMToolException; import org.teavm.tooling.TeaVMToolException;
@ -191,16 +192,18 @@ public class TeaVMBuildDaemon extends UnicastRemoteObject implements TeaVMRemote
} }
boolean errorOccurred = false; boolean errorOccurred = false;
String stackTrace = null;
try { try {
tool.generate(); tool.generate();
System.out.println("Build complete"); System.out.println("Build complete");
} catch (TeaVMToolException | RuntimeException | Error e) { } catch (TeaVMToolException | RuntimeException | Error e) {
e.printStackTrace(System.err); stackTrace = ExceptionUtil.exceptionToString(e);
errorOccurred = true; errorOccurred = true;
} }
TeaVMRemoteBuildResponse response = new TeaVMRemoteBuildResponse(); TeaVMRemoteBuildResponse response = new TeaVMRemoteBuildResponse();
response.errorOccurred = errorOccurred; response.errorOccurred = errorOccurred;
response.stackTrace = stackTrace;
response.callGraph = tool.getDependencyInfo().getCallGraph(); response.callGraph = tool.getDependencyInfo().getCallGraph();
response.problems.addAll(tool.getProblemProvider().getProblems()); response.problems.addAll(tool.getProblemProvider().getProblems());
response.severeProblems.addAll(tool.getProblemProvider().getSevereProblems()); response.severeProblems.addAll(tool.getProblemProvider().getSevereProblems());