diff --git a/src/SIL.Machine/Corpora/CorpusAlignmentException.cs b/src/SIL.Machine/Corpora/CorpusAlignmentException.cs index 2b812985..dae43706 100644 --- a/src/SIL.Machine/Corpora/CorpusAlignmentException.cs +++ b/src/SIL.Machine/Corpora/CorpusAlignmentException.cs @@ -4,14 +4,16 @@ namespace SIL.Machine.Corpora { public class CorpusAlignmentException : Exception { - public CorpusAlignmentException(string sourceRef, string targetRef) + public CorpusAlignmentException(string sourceRef, string targetRef, Exception innerException = null) : base( - $"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." + $"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.", + innerException ) { } - public CorpusAlignmentException(string[] refs) + public CorpusAlignmentException(string[] refs, Exception innerException = null) : base( - $"Invalid format in {string.Join(", ", refs)}. Mismatched key formats. There may be an extraneous tab, missing ref, or inconsistent use of user-defined refs." + $"Invalid format in {string.Join(", ", refs)}. Mismatched key formats. There may be an extraneous tab, missing ref, or inconsistent use of user-defined refs.", + innerException ) { } } } diff --git a/src/SIL.Machine/Corpora/NParallelTextCorpus.cs b/src/SIL.Machine/Corpora/NParallelTextCorpus.cs index f51970fd..18189dc8 100644 --- a/src/SIL.Machine/Corpora/NParallelTextCorpus.cs +++ b/src/SIL.Machine/Corpora/NParallelTextCorpus.cs @@ -140,9 +140,12 @@ private IEnumerable GetRows(IList> enumer ) .ToList(); } - catch (ArgumentException) + catch (ArgumentException e) { - throw new CorpusAlignmentException(currentRows.Select(e => e.Ref.ToString()).ToArray()); + throw new CorpusAlignmentException( + currentRows.Where(r => r != null).Select(r => r.Ref.ToString()).ToArray(), + e + ); } List nonMinRefIndexes = Enumerable.Range(0, N).Except(minRefIndexes).ToList(); if (minRefIndexes.Count < numberOfRemainingRows || minRefIndexes.Count(i => !completed[i]) == 1) @@ -395,9 +398,9 @@ private bool CheckSameRefRows(IList sameRefRows, TextRow otherRow) if (sameRefRows.Count > 0 && RowRefComparer.Compare(sameRefRows[0].Ref, otherRow.Ref) != 0) sameRefRows.Clear(); } - catch (ArgumentException) + catch (ArgumentException e) { - throw new CorpusAlignmentException(sameRefRows[0].Ref.ToString(), otherRow.Ref.ToString()); + throw new CorpusAlignmentException(sameRefRows[0].Ref.ToString(), otherRow.Ref.ToString(), e); } return sameRefRows.Count > 0; } diff --git a/src/SIL.Machine/Corpora/ParallelTextCorpus.cs b/src/SIL.Machine/Corpora/ParallelTextCorpus.cs index 28c54c01..382d8ff2 100644 --- a/src/SIL.Machine/Corpora/ParallelTextCorpus.cs +++ b/src/SIL.Machine/Corpora/ParallelTextCorpus.cs @@ -52,9 +52,9 @@ public override IEnumerable GetRows(IEnumerable textIds ? RowRefComparer.Compare(nRow.Ref, alignmentEnumerator.Current.Ref) : 1; } - catch (ArgumentException) + catch (ArgumentException e) { - throw new CorpusAlignmentException(nRow.NRefs.Select(r => r.ToString()).ToArray()); + throw new CorpusAlignmentException(nRow.NRefs.Select(r => r.ToString()).ToArray(), e); } } while (compareAlignmentCorpus < 0); }