Skip to content

Commit

Permalink
Change log level of line Failed to parse file ... from error to `…
Browse files Browse the repository at this point in the history
…warn` (#4602)
  • Loading branch information
ericmorand-sonarsource authored Mar 19, 2024
1 parent a80fbba commit 436e3ea
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public static void prepare() {
void parsing_error_not_on_excluded_files() {
assertThat(buildResult.getLogs())
.doesNotMatch(
"(?s).*ERROR: Failed to parse file:\\S*file-with-parsing-error-excluded\\.css.*"
"(?s).*WARN: Failed to parse file file:\\S*file-with-parsing-error-excluded\\.css.*"
)
.matches(
"(?s).*ERROR: Failed to parse file:\\S*file-with-parsing-error\\.css, line 1, Unclosed block.*"
"(?s).*WARN: Failed to parse file file:\\S*file-with-parsing-error\\.css, line 1, Unclosed block.*"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void processParsingError(BridgeServer.ParsingError parsingError) {
String message = parsingError.message;

if (line != null) {
LOG.error("Failed to parse file [{}] at line {}: {}", file, line, message);
LOG.warn("Failed to parse file [{}] at line {}: {}", file, line, message);
} else if (parsingError.code == BridgeServer.ParsingErrorCode.FAILING_TYPESCRIPT) {
LOG.error("Failed to analyze file [{}] from TypeScript: {}", file, message);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ private void saveIssues(
if (ruleKey == null) {
if ("CssSyntaxError".equals(issue.ruleId)) {
String errorMessage = issue.message.replace("(CssSyntaxError)", "").trim();
logErrorOrDebug(
logWarningOrDebug(
inputFile,
"Failed to parse {}, line {}, {}",
"Failed to parse file {}, line {}, {}",
inputFile.uri(),
issue.line,
errorMessage
Expand Down Expand Up @@ -192,6 +192,14 @@ private static void logErrorOrDebug(InputFile file, String msg, Object... argume
}
}

private static void logWarningOrDebug(InputFile file, String msg, Object... arguments) {
if (CssLanguage.KEY.equals(file.language())) {
LOG.warn(msg, arguments);
} else {
LOG.debug(msg, arguments);
}
}

@Override
protected void logErrorOrWarn(String msg, Throwable e) {
if (hasCssFiles(context)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ void test_syntax_error() throws IOException {
InputFile inputFileNotCss = addInputFile("syntax-error.html");
sensor.execute(context);
assertThat(context.allIssues()).isEmpty();
assertThat(logTester.logs(LoggerLevel.ERROR))
.contains("Failed to parse " + inputFile.uri() + ", line 2, Missed semicolon");
assertThat(logTester.logs(LoggerLevel.WARN))
.contains("Failed to parse file " + inputFile.uri() + ", line 2, Missed semicolon");
assertThat(logTester.logs(LoggerLevel.DEBUG))
.contains("Failed to parse " + inputFileNotCss.uri() + ", line 2, Missed semicolon");
.contains("Failed to parse file " + inputFileNotCss.uri() + ", line 2, Missed semicolon");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void should_raise_a_parsing_error() throws IOException {
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
assertThat(issue.primaryLocation().message()).isEqualTo("Parse error message");
assertThat(context.allAnalysisErrors()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.ERROR))
assertThat(logTester.logs(LoggerLevel.WARN))
.contains("Failed to parse file [dir/file.html] at line 1: Parse error message");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ void should_raise_a_parsing_error() throws IOException {
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(3);
assertThat(issue.primaryLocation().message()).isEqualTo("Parse error message");
assertThat(context.allAnalysisErrors()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.ERROR))
assertThat(logTester.logs(LoggerLevel.WARN))
.contains("Failed to parse file [dir/file.js] at line 3: Parse error message");
}

Expand All @@ -615,7 +615,7 @@ void should_not_create_parsing_issue_when_no_rule() throws IOException {
Collection<Issue> issues = context.allIssues();
assertThat(issues).isEmpty();
assertThat(context.allAnalysisErrors()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.ERROR))
assertThat(logTester.logs(LoggerLevel.WARN))
.contains("Failed to parse file [dir/file.js] at line 3: Parse error message");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void should_raise_a_parsing_error() throws IOException {
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(3);
assertThat(issue.primaryLocation().message()).isEqualTo("Parse error message");
assertThat(context.allAnalysisErrors()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.ERROR))
assertThat(logTester.logs(LoggerLevel.WARN))
.contains("Failed to parse file [dir/file.ts] at line 3: Parse error message");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void should_raise_a_parsing_error() throws IOException {
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
assertThat(issue.primaryLocation().message()).isEqualTo("Parse error message");
assertThat(context.allAnalysisErrors()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.ERROR))
assertThat(logTester.logs(LoggerLevel.WARN))
.contains("Failed to parse file [dir/file.yaml] at line 1: Parse error message");
}

Expand Down

0 comments on commit 436e3ea

Please sign in to comment.