Skip to content
9 changes: 8 additions & 1 deletion src/HearThis/Script/RepoMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +120,12 @@ private void MergeSkippedData(IReadOnlyList<string> defaultSkippedStyles)
/// </summary>
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);
Expand Down