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

JS-367 Survive runtime failures on saving malformed issues #4928

Merged
merged 2 commits into from
Nov 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ private void saveIssues(List<Issue> issues) {
file,
issue.line()
);
saveIssue(issue);
try {
saveIssue(issue);
} catch (RuntimeException e) {
LOG.warn("Failed to save issue in {} at line {}", file.uri(), issue.line());
LOG.warn("Exception cause", e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.sonar.plugins.javascript.bridge.BridgeServer.CpdToken;
import org.sonar.plugins.javascript.bridge.BridgeServer.Highlight;
import org.sonar.plugins.javascript.bridge.BridgeServer.HighlightedSymbol;
import org.sonar.plugins.javascript.bridge.BridgeServer.Issue;
import org.sonar.plugins.javascript.bridge.BridgeServer.Location;
import org.sonar.plugins.javascript.bridge.BridgeServer.Metrics;

Expand Down Expand Up @@ -107,4 +108,21 @@ void should_not_fail_when_invalid_cpd() {
assertThat(logTester.logs())
.contains("Failed to save CPD token in " + file.uri() + ". File will not be analyzed for duplications.");
}

@Test
void should_not_fail_when_invalid_issue() {
var fileLinesContextFactory = mock(FileLinesContextFactory.class);
when(fileLinesContextFactory.createFor(any())).thenReturn(mock(FileLinesContext.class));
var processor = new AnalysisProcessor(mock(NoSonarFilter.class), fileLinesContextFactory);
var context = SensorContextTester.create(baseDir);
var file = TestInputFileBuilder
.create("moduleKey", "file.js")
.setContents("var x = 1;")
.build();
var issue = new Issue(2, 1, 1, 2, "message", "ruleId", List.of(), 3.14, List.of()); // invalid location startLine > endLine
var response = new AnalysisResponse(null, List.of(issue), List.of(), List.of(), new Metrics(), List.of(), List.of(), null);
processor.processResponse(context, mock(JsTsChecks.class), file, response);
assertThat(logTester.logs())
.contains("Failed to save issue in " + file.uri() + " at line 2");
}
}