Skip to content

Commit 1718348

Browse files
feat: additional error handling
1 parent b03f2d8 commit 1718348

5 files changed

Lines changed: 52 additions & 15 deletions

File tree

src/main/java/org/variantsync/vevos/extraction/FastPCAnalysis.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ private record ThreadBatch(HashMap<String, GroundTruth> groundTruthMapBefore,
5858
public void onFailedParse(Analysis analysis) {
5959
RevCommit commit = analysis.getCurrentCommit();
6060

61+
extractionFailed(commit);
62+
}
63+
64+
private void extractionFailed(RevCommit commit) {
6165
synchronized (FastPCAnalysis.class) {
6266
Logger.warn("Was not able to extract ground truth for commit " + commit.getName());
6367
Serde.appendText(resultsRoot.resolve(ERROR_COMMIT_FILE), commit.getName() + "\n");
@@ -213,14 +217,23 @@ public boolean analyzeVariationDiff(Analysis analysis) {
213217
}
214218

215219
analysis.getCurrentVariationDiff().forAll(node -> {
216-
// Logger.debug("Node: {}", node);
217-
// If the file is not completely new, we consider the before case
218-
if (!(changeType == DiffEntry.ChangeType.ADD)) {
219-
PCAnalysis.analyzeNode(fileGTBefore, node, Time.BEFORE);
220-
}
221-
if (!(changeType == DiffEntry.ChangeType.DELETE)) {
222-
// If the file has not been deleted, we consider the after case
223-
PCAnalysis.analyzeNode(fileGTAfter, node, Time.AFTER);
220+
try {
221+
// Logger.debug("Node: {}", node);
222+
// If the file is not completely new, we consider the before case
223+
if (!(changeType == DiffEntry.ChangeType.ADD)) {
224+
PCAnalysis.analyzeNode(fileGTBefore, node, Time.BEFORE);
225+
}
226+
if (!(changeType == DiffEntry.ChangeType.DELETE)) {
227+
// If the file has not been deleted, we consider the after case
228+
PCAnalysis.analyzeNode(fileGTAfter, node, Time.AFTER);
229+
}
230+
} catch (MatchingException e) {
231+
Logger.error("unhandled exception while analyzing {} -> {} for commit {}.",
232+
fileNameBefore,
233+
fileNameAfter,
234+
analysis.getCurrentCommit().getName());
235+
Logger.error(e);
236+
extractionFailed(analysis.getCurrentCommit());
224237
}
225238
});
226239

src/main/java/org/variantsync/vevos/extraction/FileGT.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ protected LineAnnotation insert(int index, LineAnnotation annotation) {
8686
* @param lineNumber The line number in the current version of the file
8787
* @param matchedLine The matching line number in the counterpart version of the file
8888
*/
89-
protected void setMatching(int lineNumber, int matchedLine) {
90-
Assert.assertTrue(this.matching.get(lineNumber) == -1 || this.matching.get(lineNumber) == matchedLine,
91-
"line number mismatch for file" + this.file + " -- " + this.matching.get(lineNumber) + " : " + lineNumber);
89+
protected void setMatching(int lineNumber, int matchedLine) throws MatchingException {
90+
if (this.file.equals("/dev/null")) {
91+
// There are no valid matches for the 'null' file
92+
return;
93+
}
94+
if (this.matching.get(lineNumber) != -1 && this.matching.get(lineNumber) != matchedLine) {
95+
throw new MatchingException("line number mismatch for " + this.file + " -- " + lineNumber
96+
+ " : (" + this.matching.get(lineNumber) + " vs. " + matchedLine + ")");
97+
}
9298
this.matching.set(lineNumber, matchedLine);
9399
}
94100

@@ -158,7 +164,7 @@ public Mutable insert(LineAnnotation line) {
158164
* @param currentRange The range of lines in the current file version
159165
* @param counterpartRange The range of lines in the counterpart file version
160166
*/
161-
public void setMatching(LineRange currentRange, LineRange counterpartRange) {
167+
public void setMatching(LineRange currentRange, LineRange counterpartRange) throws MatchingException {
162168
Assert.assertTrue(!consumed);
163169
// They must span the same number of lines
164170
int lineNumber = currentRange.fromInclusive();
@@ -168,7 +174,10 @@ public void setMatching(LineRange currentRange, LineRange counterpartRange) {
168174

169175
if (matchedLine != -1) {
170176
// If there is a match, the matched regions must have the same size
171-
Assert.assertEquals(endNumber-lineNumber, matchEnd-matchedLine);
177+
if(endNumber-lineNumber != matchEnd-matchedLine) {
178+
throw new MatchingException("line number mismatch for file" + this.file + " -- ; " +
179+
"ranges have different size " + (endNumber-lineNumber) + " : " + (matchEnd-matchedLine));
180+
}
172181
// Set the matches
173182
for (; lineNumber < currentRange.toExclusive(); lineNumber++, matchedLine++) {
174183
this.setMatching(lineNumber, matchedLine);

src/main/java/org/variantsync/vevos/extraction/FullPCAnalysis.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ public boolean analyzeVariationDiff(Analysis analysis) throws Exception {
7575

7676
analysis.getCurrentVariationDiff().forAll(node -> {
7777
// Logger.debug("Node: {}", node);
78-
PCAnalysis.analyzeNode(fileGT, node, Time.AFTER);
78+
try {
79+
PCAnalysis.analyzeNode(fileGT, node, Time.AFTER);
80+
} catch (MatchingException e) {
81+
Logger.error("unhandled exception while analyzing {} -> {} for commit {}.",
82+
fileNameBefore,
83+
fileNameAfter,
84+
analysis.getCurrentCommit().getName());
85+
}
7986
});
8087

8188
return true;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.variantsync.vevos.extraction;
2+
3+
public class MatchingException extends Exception {
4+
5+
public MatchingException(String message) {
6+
super(message);
7+
}
8+
}

src/main/java/org/variantsync/vevos/extraction/PCAnalysis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface PCAnalysis {
1818
* @param node The node that is to be analyzed
1919
* @param time Whether we should handle the node as before or after the edit
2020
*/
21-
static void analyzeNode(FileGT.Mutable fileGT, DiffNode<DiffLinesLabel> node, Time time) {
21+
static void analyzeNode(FileGT.Mutable fileGT, DiffNode<DiffLinesLabel> node, Time time) throws MatchingException {
2222
if (time == Time.BEFORE && node.diffType == DiffType.ADD) {
2323
return;
2424
}

0 commit comments

Comments
 (0)