Skip to content

Commit f7ae987

Browse files
authored
Improve alignment exception error reporting (#399)
1 parent d1390f7 commit f7ae987

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/SIL.Machine/Corpora/CorpusAlignmentException.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ namespace SIL.Machine.Corpora
44
{
55
public class CorpusAlignmentException : Exception
66
{
7-
public CorpusAlignmentException(string sourceRef, string targetRef)
7+
public CorpusAlignmentException(string sourceRef, string targetRef, Exception innerException = null)
88
: base(
9-
$"Invalid format in {sourceRef} and {targetRef}. Mismatched key formats \"{sourceRef}\" and \"{targetRef}\". There may be an extraneous tab, missing ref, or inconsistent use of user-defined refs."
9+
$"Invalid format in {sourceRef} and {targetRef}. Mismatched key formats \"{sourceRef}\" and \"{targetRef}\". There may be an extraneous tab, missing ref, or inconsistent use of user-defined refs.",
10+
innerException
1011
) { }
1112

12-
public CorpusAlignmentException(string[] refs)
13+
public CorpusAlignmentException(string[] refs, Exception innerException = null)
1314
: base(
14-
$"Invalid format in {string.Join(", ", refs)}. Mismatched key formats. There may be an extraneous tab, missing ref, or inconsistent use of user-defined refs."
15+
$"Invalid format in {string.Join(", ", refs)}. Mismatched key formats. There may be an extraneous tab, missing ref, or inconsistent use of user-defined refs.",
16+
innerException
1517
) { }
1618
}
1719
}

src/SIL.Machine/Corpora/NParallelTextCorpus.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ private IEnumerable<NParallelTextRow> GetRows(IList<IEnumerator<TextRow>> enumer
140140
)
141141
.ToList();
142142
}
143-
catch (ArgumentException)
143+
catch (ArgumentException e)
144144
{
145-
throw new CorpusAlignmentException(currentRows.Select(e => e.Ref.ToString()).ToArray());
145+
throw new CorpusAlignmentException(
146+
currentRows.Where(r => r != null).Select(r => r.Ref.ToString()).ToArray(),
147+
e
148+
);
146149
}
147150
List<int> nonMinRefIndexes = Enumerable.Range(0, N).Except(minRefIndexes).ToList();
148151
if (minRefIndexes.Count < numberOfRemainingRows || minRefIndexes.Count(i => !completed[i]) == 1)
@@ -395,9 +398,9 @@ private bool CheckSameRefRows(IList<TextRow> sameRefRows, TextRow otherRow)
395398
if (sameRefRows.Count > 0 && RowRefComparer.Compare(sameRefRows[0].Ref, otherRow.Ref) != 0)
396399
sameRefRows.Clear();
397400
}
398-
catch (ArgumentException)
401+
catch (ArgumentException e)
399402
{
400-
throw new CorpusAlignmentException(sameRefRows[0].Ref.ToString(), otherRow.Ref.ToString());
403+
throw new CorpusAlignmentException(sameRefRows[0].Ref.ToString(), otherRow.Ref.ToString(), e);
401404
}
402405
return sameRefRows.Count > 0;
403406
}

src/SIL.Machine/Corpora/ParallelTextCorpus.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public override IEnumerable<ParallelTextRow> GetRows(IEnumerable<string> textIds
5252
? RowRefComparer.Compare(nRow.Ref, alignmentEnumerator.Current.Ref)
5353
: 1;
5454
}
55-
catch (ArgumentException)
55+
catch (ArgumentException e)
5656
{
57-
throw new CorpusAlignmentException(nRow.NRefs.Select(r => r.ToString()).ToArray());
57+
throw new CorpusAlignmentException(nRow.NRefs.Select(r => r.ToString()).ToArray(), e);
5858
}
5959
} while (compareAlignmentCorpus < 0);
6060
}

0 commit comments

Comments
 (0)