From e0999dc9ae57fd89739e65682f3496fc59a29d15 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Tue, 16 Aug 2022 15:41:12 -0400 Subject: [PATCH] Bug fix #358 : pdf downoad errors in CLI were crashing the rest of the loop --- Source/LibationCli/Options/LiberateOptions.cs | 5 +++-- .../LibationCli/Options/_ProcessableOptionsBase.cs | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/LibationCli/Options/LiberateOptions.cs b/Source/LibationCli/Options/LiberateOptions.cs index 6563c778..5c904771 100644 --- a/Source/LibationCli/Options/LiberateOptions.cs +++ b/Source/LibationCli/Options/LiberateOptions.cs @@ -25,9 +25,10 @@ private static Processable CreateBackupBook() var downloadPdf = CreateProcessable(); //Chain pdf download on DownloadDecryptBook.Completed - async void onDownloadDecryptBookCompleted(object sender, LibraryBook e) + void onDownloadDecryptBookCompleted(object sender, LibraryBook e) { - await downloadPdf.TryProcessAsync(e); + // this is fast anyway. run as sync for easy exception catching + downloadPdf.TryProcessAsync(e).GetAwaiter().GetResult(); } var downloadDecryptBook = CreateProcessable(onDownloadDecryptBookCompleted); diff --git a/Source/LibationCli/Options/_ProcessableOptionsBase.cs b/Source/LibationCli/Options/_ProcessableOptionsBase.cs index 0897c6b9..e4b255e1 100644 --- a/Source/LibationCli/Options/_ProcessableOptionsBase.cs +++ b/Source/LibationCli/Options/_ProcessableOptionsBase.cs @@ -19,7 +19,17 @@ protected static TProcessable CreateProcessable(EventHandler Console.WriteLine($"{typeof(TProcessable).Name} Begin: {e}"); strProc.Completed += (o, e) => Console.WriteLine($"{typeof(TProcessable).Name} Completed: {e}"); - strProc.Completed += completedAction; + strProc.Completed += (s, e) => + { + try + { + completedAction?.Invoke(s, e); + } + catch (Exception ex) + { + Serilog.Log.Logger.Error(ex, "CLI error"); + } + }; return strProc; }