diff --git a/Source/LibationAvalonia/ViewModels/MainVM.VisibleBooks.cs b/Source/LibationAvalonia/ViewModels/MainVM.VisibleBooks.cs index 67eb8b95..d0a8e0d2 100644 --- a/Source/LibationAvalonia/ViewModels/MainVM.VisibleBooks.cs +++ b/Source/LibationAvalonia/ViewModels/MainVM.VisibleBooks.cs @@ -199,8 +199,19 @@ partial class MainVM private async Task setLiberatedVisibleMenuItemAsync() { - var visible = ProductsDisplay.GetVisibleBookEntries(); - var libraryStats = await Task.Run(() => LibraryCommands.GetCounts(visible)); - await Dispatcher.UIThread.InvokeAsync(() => setVisibleNotLiberatedCount(libraryStats.PendingBooks)); + try + { + var visible = ProductsDisplay.GetVisibleBookEntries(); + var libraryStats = await Task.Run(() => LibraryCommands.GetCounts(visible)); + await Dispatcher.UIThread.InvokeAsync(() => setVisibleNotLiberatedCount(libraryStats.PendingBooks)); + } + // Every caller is an async void event handler, where a failure is not a faulted task anyone awaits but + // an unhandled exception that closes Libation. Counting these books reads the file system, which can + // fail at any moment for reasons that have nothing to do with the app - a Books folder on a drive that + // was just unplugged is enough. A stale number above a menu item is not worth the session. + catch (Exception ex) + { + Serilog.Log.Logger.Error(ex, "Error counting the visible books which are not yet liberated"); + } } } diff --git a/Source/LibationWinForms/Form1.VisibleBooks.cs b/Source/LibationWinForms/Form1.VisibleBooks.cs index 8d07862a..db186125 100644 --- a/Source/LibationWinForms/Form1.VisibleBooks.cs +++ b/Source/LibationWinForms/Form1.VisibleBooks.cs @@ -28,6 +28,22 @@ public partial class Form1 private static DateTime lastVisibleCountUpdated; void setLiberatedVisibleMenuItem() + { + try + { + setLiberatedVisibleMenuItemCore(); + } + // Both callers are async void event handlers, where a failure is not a faulted task anyone awaits but + // an unhandled exception that closes Libation. Counting these books reads the file system, which can + // fail at any moment for reasons that have nothing to do with the app - a Books folder on a drive that + // was just unplugged is enough. A stale number above a menu item is not worth the session. + catch (Exception ex) + { + Serilog.Log.Logger.Error(ex, "Error counting the visible books which are not yet liberated"); + } + } + + private void setLiberatedVisibleMenuItemCore() { //Assume that all calls to update arrive in order, //Only display results of the latest book count.