From 46b7cb37bd0bcb2273d58774c5cd21b64351b792 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 15 Dec 2021 22:04:41 +0000 Subject: [PATCH] adding explicit handling for null item in watcher, skipping user watchers without spotify link, fixed weird systemd issue with async run --- Selector.CLI/DbWatcherService.cs | 4 +++- Selector.CLI/Program.cs | 3 +-- Selector/Watcher/PlayerWatcher.cs | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Selector.CLI/DbWatcherService.cs b/Selector.CLI/DbWatcherService.cs index e34ffbc..f9ecba6 100644 --- a/Selector.CLI/DbWatcherService.cs +++ b/Selector.CLI/DbWatcherService.cs @@ -83,7 +83,9 @@ namespace Selector.CLI var indices = new HashSet(); - foreach (var dbWatcher in db.Watcher.Include(w => w.User)) + foreach (var dbWatcher in db.Watcher + .Include(w => w.User) + .Where(w => !string.IsNullOrWhiteSpace(w.User.SpotifyRefreshToken))) { Logger.LogInformation($"Creating new [{dbWatcher.Type}] watcher"); diff --git a/Selector.CLI/Program.cs b/Selector.CLI/Program.cs index f580305..01d4c8f 100644 --- a/Selector.CLI/Program.cs +++ b/Selector.CLI/Program.cs @@ -26,8 +26,7 @@ namespace Selector.CLI } }; - var host = CreateHostBuilder(args, ConfigureDefault, ConfigureDefaultNlog); - await host.RunConsoleAsync(); + CreateHostBuilder(args, ConfigureDefault, ConfigureDefaultNlog).Build().Run(); } public static RootOptions ConfigureOptions(HostBuilderContext context, IServiceCollection services) diff --git a/Selector/Watcher/PlayerWatcher.cs b/Selector/Watcher/PlayerWatcher.cs index b613e73..02d0ae9 100644 --- a/Selector/Watcher/PlayerWatcher.cs +++ b/Selector/Watcher/PlayerWatcher.cs @@ -130,6 +130,14 @@ namespace Selector OnItemChange(GetEvent()); } } + else if (Previous.Item is null) + { + Logger.LogWarning($"Previous item was null [{Previous.DisplayString()}]"); + } + else if (Live.Item is null) + { + Logger.LogWarning($"Live item was null [{Live.DisplayString()}]"); + } else { Logger.LogError($"Unknown combination of previous and current playing contexts, [{Previous.DisplayString()}] [{Live.DisplayString()}]"); throw new NotSupportedException("Unknown item combination");