@@ -135,6 +135,9 @@ public async Task MarkTrackAsFinished(NotificationDetail trackDetail)
135135 var next = await GetNextBibleChapter ( trackDetail . LanguageCode , trackDetail . PublicationCode ,
136136 trackDetail . BookNumber , trackDetail . ChapterNumber ) ;
137137
138+ if ( next . Key == null || next . Value == null )
139+ throw new InvalidOperationException ( $ "Next chapter Key or Value is null") ;
140+
138141 bibleReadingSchedule . BookNumber = next . Key . Number ;
139142 bibleReadingSchedule . ChapterNumber = next . Value . Number ;
140143 bibleReadingSchedule . FinishedDuration = TimeSpan . Zero ;
@@ -227,6 +230,8 @@ public async Task<List<PlayItem>> NextTracks(long scheduleId)
227230 }
228231
229232 var chapterDetail = chapters [ chapter ] ;
233+ if ( chapterDetail . Source == null )
234+ throw new InvalidOperationException ( $ "Chapter { chapter } Source is null in book { bookNumber } ") ;
230235
231236 var publicationCode = bibleReadingSchedule . PublicationCode ;
232237 var languageCode = bibleReadingSchedule . LanguageCode ;
@@ -267,6 +272,11 @@ public async Task<List<PlayItem>> NextTracks(long scheduleId)
267272 bibleReadingSchedule . PublicationCode ,
268273 bookNumber , chapter ) ;
269274
275+ if ( next . Key == null || next . Value == null )
276+ throw new InvalidOperationException ( $ "Next chapter Key or Value is null") ;
277+ if ( next . Value . Source == null )
278+ throw new InvalidOperationException ( $ "Next chapter Source is null") ;
279+
270280 bookNumber = next . Key . Number ;
271281 chapter = next . Value . Number ;
272282 url = next . Value . Source . Url ;
@@ -323,8 +333,11 @@ public async Task MoveToPreviousBibleChapter(long scheduleId)
323333
324334 var previous = await GetPreviousBibleChapter ( languageCode , publicationCode , bookNumber , chapter ) ;
325335
326- bibleReadingSchedule . BookNumber = previous . Key . Number ;
327- bibleReadingSchedule . ChapterNumber = previous . Value . Number ;
336+ if ( previous . Key == null || previous . Value == null )
337+ throw new InvalidOperationException ( $ "Previous chapter Key or Value is null") ;
338+
339+ bibleReadingSchedule . BookNumber = previous . Key . Number ;
340+ bibleReadingSchedule . ChapterNumber = previous . Value . Number ;
328341 bibleReadingSchedule . FinishedDuration = TimeSpan . Zero ;
329342
330343 await scheduleDbContext . SaveChangesAsync ( ) ;
@@ -432,6 +445,9 @@ private async Task<PlayItem> NextMusicUrlToPlay(AlarmSchedule schedule, bool nex
432445 throw new InvalidOperationException ( $ "Invalid track index { melodyTrackIndex } for { melodyTracks . Count } tracks") ;
433446
434447 var melodyTrack = melodyTracks [ melodyTrackIndex ] ;
448+ if ( melodyTrack . Source == null )
449+ throw new InvalidOperationException ( $ "Melody track { melodyTrackIndex } Source is null") ;
450+
435451 return new PlayItem ( new NotificationDetail
436452 {
437453 ScheduleId = schedule . Id ,
@@ -452,6 +468,9 @@ private async Task<PlayItem> NextMusicUrlToPlay(AlarmSchedule schedule, bool nex
452468 throw new InvalidOperationException ( $ "Invalid track index { vocalTrackIndex } for { vocalTracks . Count } tracks") ;
453469
454470 var vocalTrack = vocalTracks [ vocalTrackIndex ] ;
471+ if ( vocalTrack . Source == null )
472+ throw new InvalidOperationException ( $ "Vocal track { vocalTrackIndex } Source is null") ;
473+
455474 return new PlayItem ( new NotificationDetail
456475 {
457476 ScheduleId = schedule . Id ,
0 commit comments