Skip to content

Commit f77d928

Browse files
committed
Add try/catch block and logger call in post-parsing action to make future debugging easier
1 parent 2d7e28a commit f77d928

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/TextDocumentState.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,26 +205,33 @@ private void parse() {
205205
try {
206206
parser.apply(location, content)
207207
.whenCompleteAsync((ITree t, Throwable e) -> {
208-
if (e instanceof CompletionException && e.getCause() != null) {
209-
e = e.getCause();
210-
}
211-
var diagnosticsList = toDiagnosticsList(t, e); // `t` and `e` are nullable
212-
213-
// Complete future to get the tree
214-
if (t == null) {
215-
treeAsync.completeExceptionally(e);
216-
} else {
217-
var tree = new Versioned<>(version, t, timestamp);
218-
Versioned.replaceIfNewer(last, tree);
219-
if (diagnosticsList.isEmpty()) {
220-
Versioned.replaceIfNewer(lastWithoutErrors, tree);
208+
try {
209+
if (e instanceof CompletionException && e.getCause() != null) {
210+
e = e.getCause();
211+
}
212+
var diagnosticsList = toDiagnosticsList(t, e); // `t` and `e` are nullable
213+
214+
// Complete future to get the tree
215+
if (t == null) {
216+
treeAsync.completeExceptionally(e);
217+
} else {
218+
var tree = new Versioned<>(version, t, timestamp);
219+
Versioned.replaceIfNewer(last, tree);
220+
if (diagnosticsList.isEmpty()) {
221+
Versioned.replaceIfNewer(lastWithoutErrors, tree);
222+
}
223+
treeAsync.complete(tree);
221224
}
222-
treeAsync.complete(tree);
223-
}
224225

225-
// Complete future to get diagnostics
226-
var diagnostics = new Versioned<>(version, diagnosticsList);
227-
diagnosticsAsync.complete(diagnostics);
226+
// Complete future to get diagnostics
227+
var diagnostics = new Versioned<>(version, diagnosticsList);
228+
diagnosticsAsync.complete(diagnostics);
229+
} catch (Exception exc) {
230+
// The action of `whenCompleteAsync` shouldn't throw an exception (see JavaDoc): if it
231+
// unexpectedly does, then it is almost surely a bug, but the exception is swallowed, so it
232+
// is very hard to debug. The try/catch block and logger call aim to make it easier.
233+
logger.error("Unexpected exception after parsing: {}", exc);
234+
}
228235
}, exec);
229236
} catch (NoContributionException e) {
230237
logger.debug("Ignoring missing parser for {}", location, e);

0 commit comments

Comments
 (0)