diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs index 8edb543..f0f6619 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs @@ -135,10 +135,7 @@ public class BaseItemAnalyzerTask try { - if (ct.IsCancellationRequested) - { - return; - } + ct.ThrowIfCancellationRequested(); foreach (AnalysisMode mode in requiredModes) { @@ -150,6 +147,10 @@ public class BaseItemAnalyzerTask progress.Report(totalProcessed * 100 / totalQueued); } } + catch (OperationCanceledException ex) + { + _logger.LogDebug(ex, "Analysis cancelled"); + } catch (FingerprintException ex) { _logger.LogWarning( @@ -158,6 +159,11 @@ public class BaseItemAnalyzerTask first.SeasonNumber, ex); } + catch (Exception ex) + { + _logger.LogError(ex, "An unexpected error occurred during analysis"); + throw; + } if (Plugin.Instance.Configuration.RegenerateMediaSegments || (updateManagers && Plugin.Instance.Configuration.UpdateMediaSegments)) { @@ -238,6 +244,7 @@ public class BaseItemAnalyzerTask foreach (var analyzer in analyzers) { items = analyzer.AnalyzeMediaFiles(items, mode, cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); } // Add items without intros/credits to blacklist. diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs index cbca925..6f72cf1 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs @@ -164,6 +164,10 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Services { await PerformAnalysisAsync().ConfigureAwait(false); } + catch (OperationCanceledException) + { + _logger.LogInformation("Automatic Analysis task cancelled"); + } catch (Exception ex) { _logger.LogError(ex, "Error in RunAnalysisAsync");