Skip to content

Commit

Permalink
Skip file when there is a failure saving CPD token (#4660)
Browse files Browse the repository at this point in the history
  • Loading branch information
saberduck authored Apr 11, 2024
1 parent ed1f613 commit 5950215
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,16 @@ private void saveCpd(BridgeServer.CpdToken[] cpdTokens) {
// even providing empty 'NewCpdTokens' will trigger duplication computation so skipping
return;
}
NewCpdTokens newCpdTokens = context.newCpdTokens().onFile(file);
for (BridgeServer.CpdToken cpdToken : cpdTokens) {
try {
try {
NewCpdTokens newCpdTokens = context.newCpdTokens().onFile(file);
for (BridgeServer.CpdToken cpdToken : cpdTokens) {
newCpdTokens.addToken(cpdToken.location.toTextRange(file), cpdToken.image);
} catch (IllegalArgumentException e) {
LOG.warn("Failed to save CPD token in {} at {}", file.uri(), cpdToken.location);
LOG.warn("Exception cause", e);
// continue processing other tokens
}
newCpdTokens.save();
} catch (IllegalArgumentException e) {
LOG.warn("Failed to save CPD token in {}. File will not be analyzed for duplications.", file.uri());
LOG.warn("Exception cause", e);
}
newCpdTokens.save();
}

void saveIssue(BridgeServer.Issue issue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void should_not_fail_when_invalid_cpd() {
cpd.location = new BridgeServer.Location(1, 2, 1, 1); // invalid range startCol > endCol
response.cpdTokens = new BridgeServer.CpdToken[] { cpd };
processor.processResponse(context, mock(JsTsChecks.class), file, response);
assertThat(context.cpdTokens(file.key())).isNull();
assertThat(logTester.logs())
.contains("Failed to save CPD token in " + file.uri() + " at 1:2-1:1");
.contains("Failed to save CPD token in " + file.uri() + ". File will not be analyzed for duplications.");
}
}

0 comments on commit 5950215

Please sign in to comment.