Skip to content

Commit 46a4f10

Browse files
committed
Add line number extraction for error explanation
1 parent b221610 commit 46a4f10

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/main/java/io/jenkins/plugins/explain_error/ErrorExplainer.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,21 @@ private String extractErrorLogs(Run<?, ?> run, String logPattern, int maxLines)
7070
Pattern pattern = Pattern.compile(logPattern, Pattern.CASE_INSENSITIVE);
7171
StringBuilder errorLogs = new StringBuilder();
7272

73-
for (String line : logLines) {
74-
if (pattern.matcher(line).find()) {
75-
errorLogs.append(line).append("\n");
76-
}
77-
}
73+
for (int i = 0; i < logLines.size(); i++) {
74+
String line = logLines.get(i);
75+
76+
if (pattern.matcher(line).find()) {
77+
int lineNumber = i + 1; // 1-indexed
78+
LOGGER.fine("Matched error at line: " + lineNumber);
79+
80+
errorLogs.append("[Line ")
81+
.append(lineNumber)
82+
.append("] ")
83+
.append(line)
84+
.append("\n");
85+
}
86+
}
87+
7888

7989
return errorLogs.toString();
8090
}

0 commit comments

Comments
 (0)