Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix analysis running with invalid config #65

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

import java.io.File;

public class Main {
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/analysis/GoblintAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public class GoblintAnalysis implements ServerAnalysis {
private final GobPieConfiguration gobpieConfiguration;
private final FileWatcher goblintConfWatcher;

private static Future<?> lastAnalysisTask;
private static boolean configValid = false;
private static Future<?> lastAnalysisTask = null;

private final Logger log = LogManager.getLogger(GoblintAnalysis.class);

Expand Down Expand Up @@ -115,19 +116,23 @@ public void analyze(Collection<? extends Module> files, AnalysisConsumer consume
}
}

magpieServer.forwardMessageToClient(new MessageParams(MessageType.Info, source() + " started analyzing the code."));

refreshGoblintConfig();

if (!configValid) {
return;
}

magpieServer.forwardMessageToClient(new MessageParams(MessageType.Info, source() + " started analyzing the code."));

preAnalyse();

log.info("---------------------- Analysis started ----------------------");
lastAnalysisTask = reanalyse().thenAccept(response -> {
consumer.consume(new ArrayList<>(response), source());
log.info("--------------------- Analysis finished ----------------------");
magpieServer.forwardMessageToClient(new MessageParams(MessageType.Info, source() + " finished analyzing the code."));
}).exceptionally(e -> {
Throwable cause = e instanceof CompletionException ce ? ce.getCause() : e;
}).exceptionally(ex -> {
Throwable cause = ex instanceof CompletionException ? ex.getCause() : ex;
// TODO: handle closed socket exceptions:
// org.eclipse.lsp4j.jsonrpc.JsonRpcException: java.net.SocketException: Broken pipe; errno=32
// and org.eclipse.lsp4j.jsonrpc.JsonRpcException: org.newsclub.net.unix.SocketClosedException: Not open
Expand All @@ -151,18 +156,22 @@ private void abortAnalysis() throws IOException {


/**
* Reloads Goblint config if it has been changed
* Reloads Goblint config if it has been changed or is currently invalid.
*/
private void refreshGoblintConfig() {
if (goblintConfWatcher.checkModified()) {
goblintService.reset_config()
if (goblintConfWatcher.checkModified() || !configValid) {
configValid = goblintService.reset_config()
.thenCompose(_res ->
goblintService.read_config(new Params(new File(gobpieConfiguration.getGoblintConf()).getAbsolutePath())))
.exceptionally(ex -> {
String msg = "Goblint was unable to successfully read the new configuration: " + ex.getMessage();
magpieServer.forwardMessageToClient(new MessageParams(MessageType.Warning, msg));
log.error(msg);
return null;
.handle((_res, ex) -> {
if (ex != null) {
Throwable cause = ex instanceof CompletionException ? ex.getCause() : ex;
String msg = "Goblint was unable to successfully read the new configuration: " + cause.getMessage();
magpieServer.forwardMessageToClient(new MessageParams(MessageType.Error, msg));
log.error(msg);
return false;
}
return true;
})
.join();
}
Expand Down