Skip to content

Commit

Permalink
🐛 fix maven build error edge case (#503)
Browse files Browse the repository at this point in the history
* 🐛 fix maven build error edge case

Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>

* 👻 make build error pattern

Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>

---------

Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad authored Nov 27, 2024
1 parent 8b27d4a commit 73e3b79
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
15 changes: 10 additions & 5 deletions kai/reactive_codeplanner/task_runner/compiler/maven_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

tracer = trace.get_tracer("maven_validator")

BUILD_ERROR_PATTERN = re.compile(
r"\s*\[(ERROR|FATAL)\]\s*(.+?) @ line (\d+), column (\d+)"
)


class MavenCompileStep(ValidationStep):

Expand Down Expand Up @@ -263,7 +267,11 @@ def parse_build_errors(
# Collect details if any
details = []
i += 1
while i < len(lines) and lines[i].startswith("[ERROR] "):
while (
i < len(lines)
and lines[i].startswith("[ERROR] ")
and not BUILD_ERROR_PATTERN.match(lines[i])
):
detail_line = lines[i].replace("[ERROR] ", "", 1).strip()
details.append(detail_line)
i += 1
Expand Down Expand Up @@ -360,10 +368,7 @@ def match_build_error(line: str, file_path: str) -> Optional[MavenCompilerError]
"""
Matches a build error line and returns a BuildError instance.
"""
build_error_pattern = re.compile(
r"\s*\[(ERROR|FATAL)\]\s*(.+?) @ line (\d+), column (\d+)"
)
match = build_error_pattern.match(line)
match = BUILD_ERROR_PATTERN.match(line)
if match:
message = match.group(2).strip()
line_number = int(match.group(3))
Expand Down
16 changes: 16 additions & 0 deletions tests/test_maven_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,22 @@ def test_bad_pom_error(self) -> None:
self.assertEqual(len(errors), 1)
self.assertEqual(errors[0].file, "/kai/example/coolstore/pom.xml")

def test_multiple_build_errors(self) -> None:
mvn_output = """[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] The project com.redhat.coolstore:monolith:1.0.0-SNAPSHOT (/Users/pgaikwad/Projects/kai/example/coolstore/pom.xml) has 2 errors
[ERROR] 'dependencies.dependency.version' for io.quarkus:quarkus-jakartaee-jaxrs:jar is missing. @ line 30, column 21
[ERROR] 'dependencies.dependency.version' for io.quarkus:quarkus-jakartaee-jms:jar is missing. @ line 34, column 21
[ERROR]
"""
build_errors, dependency_errors, compilation_errors, catchall_errors = (
parse_maven_output(mvn_output, rc=1)
)
self.assertEqual(len(build_errors), 2)
self.assertEqual(len(dependency_errors), 0)
self.assertEqual(len(compilation_errors), 0)
self.assertEqual(len(catchall_errors), 0)


if __name__ == "__main__":
unittest.main()

0 comments on commit 73e3b79

Please sign in to comment.