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

Change log level of line Failed to parse file ... from error to warn #4602

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
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
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
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
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
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