Skip to content

Commit

Permalink
Merge pull request #65 from FeldrinH/fix-invalid-config
Browse files Browse the repository at this point in the history
Fix analysis running with invalid config
  • Loading branch information
karoliineh authored Aug 14, 2023
2 parents 3ffbdb7 + 8a2b8bb commit 7666953
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
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

0 comments on commit 7666953

Please sign in to comment.