diff --git a/src/HearThis/Script/RepoMerger.cs b/src/HearThis/Script/RepoMerger.cs index d701e7e0..6ee007d1 100644 --- a/src/HearThis/Script/RepoMerger.cs +++ b/src/HearThis/Script/RepoMerger.cs @@ -10,12 +10,14 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Linq; using System.Xml.XPath; using HearThis.Communication; using SIL.Progress; +using SIL.Reporting; using SIL.Windows.Forms.Extensions; using SIL.Xml; using static SIL.Windows.Forms.Extensions.ControlExtensions.ErrorHandlingAction; @@ -118,7 +120,12 @@ private void MergeSkippedData(IReadOnlyList defaultSkippedStyles) /// public virtual void MergeChapter(int iBook, int iChap1Based) { - var book = _project.Books[iBook]; + var book = _project.Books.FirstOrDefault(b => b.BookNumber == iBook); + if (book == null) + { + Logger.WriteEvent($"Attempted to merge a chapter for a non-existent book: {iBook}"); + return; + } var ourInfo = GetXmlInfo(_mine, Path.Combine(GetOurChapterPath(_project.Name, book.Name, iChap1Based), ChapterInfo.kChapterInfoFilename)); var chapInfo = string.IsNullOrEmpty(ourInfo) ? book.GetChapter(iChap1Based) : ChapterInfo.Create(book, iChap1Based, ourInfo, true);