Skip to content

Commit

Permalink
JS-209 Catch IllegalStateException when saving highlights and cpd tok…
Browse files Browse the repository at this point in the history
…ens (#4746)
  • Loading branch information
vdiez authored Jun 21, 2024
1 parent 919578d commit 4df23d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,18 @@ private void saveHighlights(List<Highlight> highlights) {
highlight.location().toTextRange(file),
TypeOfText.valueOf(highlight.textType())
);
} catch (IllegalArgumentException e) {
LOG.warn("Failed to save highlight in {} at {}", file.uri(), highlight.location());
} catch (RuntimeException e) {
LOG.warn("Failed to create highlight in {} at {}", file.uri(), highlight.location());
LOG.warn("Exception cause", e);
// continue processing other highlights
}
}
highlighting.save();
try {
highlighting.save();
} catch (RuntimeException e) {
LOG.warn("Failed to save highlights in {}.", file.uri());
LOG.warn("Exception cause", e);
}
}

private void saveHighlightedSymbols(List<HighlightedSymbol> highlightedSymbols) {
Expand All @@ -222,7 +227,7 @@ private void saveHighlightedSymbols(List<HighlightedSymbol> highlightedSymbols)
declaration.endLine(),
declaration.endCol()
);
} catch (IllegalArgumentException e) {
} catch (RuntimeException e) {
LOG.warn("Failed to create symbol declaration in {} at {}", file.uri(), declaration);
continue;
}
Expand All @@ -234,7 +239,7 @@ private void saveHighlightedSymbols(List<HighlightedSymbol> highlightedSymbols)
reference.endLine(),
reference.endCol()
);
} catch (IllegalArgumentException e) {
} catch (RuntimeException e) {
LOG.warn("Failed to create symbol reference in {} at {}", file.uri(), reference);
}
}
Expand Down Expand Up @@ -291,7 +296,7 @@ private void saveCpd(List<CpdToken> cpdTokens) {
newCpdTokens.addToken(cpdToken.location().toTextRange(file), cpdToken.image());
}
newCpdTokens.save();
} catch (IllegalArgumentException e) {
} catch (RuntimeException e) {
LOG.warn("Failed to save CPD token in {}. File will not be analyzed for duplications.", file.uri());
LOG.warn("Exception cause", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void should_not_fail_when_invalid_range() {
var response = new AnalysisResponse(null, List.of(), List.of(highlight), List.of(), new Metrics(), List.of(), List.of(), null);
processor.processResponse(context, mock(JsTsChecks.class), file, response);
assertThat(logTester.logs())
.contains("Failed to save highlight in " + file.uri() + " at 1:2-1:1");
.contains("Failed to create highlight in " + file.uri() + " at 1:2-1:1");
}

@Test
Expand Down

0 comments on commit 4df23d0

Please sign in to comment.