From a84c8a0efc4c1e9fb7acc99514095d010150b2f7 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sat, 19 Aug 2023 13:24:05 -0500 Subject: [PATCH] refactor: Improve service connection error message When unable to connect to a service, we no longer send a confusing message saying capabilities could not be obtained. This also involved removing nullability in a few places to simplify logic an error handling. --- .../SonarrReleaseProfileCompatibilityHandler.cs | 5 ----- .../ApiServices/System/IServiceInformation.cs | 2 +- .../ApiServices/System/ServiceInformation.cs | 10 ++++------ .../Radarr/IRadarrCapabilityFetcher.cs | 2 +- .../Radarr/RadarrCapabilityEnforcer.cs | 7 +------ .../Compatibility/ServiceCapabilityFetcher.cs | 4 ++-- .../Sonarr/ISonarrCapabilityFetcher.cs | 2 +- .../Sonarr/SonarrCapabilityEnforcer.cs | 4 ---- .../Sonarr/SonarrCapabilityEnforcerTest.cs | 14 -------------- 9 files changed, 10 insertions(+), 40 deletions(-) diff --git a/src/Recyclarr.Cli/Pipelines/ReleaseProfile/Api/SonarrReleaseProfileCompatibilityHandler.cs b/src/Recyclarr.Cli/Pipelines/ReleaseProfile/Api/SonarrReleaseProfileCompatibilityHandler.cs index 374f71ab..47e92ada 100644 --- a/src/Recyclarr.Cli/Pipelines/ReleaseProfile/Api/SonarrReleaseProfileCompatibilityHandler.cs +++ b/src/Recyclarr.Cli/Pipelines/ReleaseProfile/Api/SonarrReleaseProfileCompatibilityHandler.cs @@ -5,7 +5,6 @@ using Recyclarr.Cli.Pipelines.ReleaseProfile.Api.Objects; using Recyclarr.Cli.Pipelines.ReleaseProfile.Api.Schemas; using Recyclarr.TrashLib.Compatibility.Sonarr; using Recyclarr.TrashLib.Config.Services; -using Recyclarr.TrashLib.ExceptionTypes; namespace Recyclarr.Cli.Pipelines.ReleaseProfile.Api; @@ -30,10 +29,6 @@ public class SonarrReleaseProfileCompatibilityHandler : ISonarrReleaseProfileCom SonarrReleaseProfile profile) { var capabilities = await _capabilityFetcher.GetCapabilities(config); - if (capabilities is null) - { - throw new ServiceIncompatibilityException("Capabilities could not be obtained"); - } return capabilities.ArraysNeededForReleaseProfileRequiredAndIgnored ? profile diff --git a/src/Recyclarr.TrashLib/ApiServices/System/IServiceInformation.cs b/src/Recyclarr.TrashLib/ApiServices/System/IServiceInformation.cs index 013a9620..7598ad79 100644 --- a/src/Recyclarr.TrashLib/ApiServices/System/IServiceInformation.cs +++ b/src/Recyclarr.TrashLib/ApiServices/System/IServiceInformation.cs @@ -4,5 +4,5 @@ namespace Recyclarr.TrashLib.ApiServices.System; public interface IServiceInformation { - public Task GetVersion(IServiceConfiguration config); + public Task GetVersion(IServiceConfiguration config); } diff --git a/src/Recyclarr.TrashLib/ApiServices/System/ServiceInformation.cs b/src/Recyclarr.TrashLib/ApiServices/System/ServiceInformation.cs index b2c5661e..934449ea 100644 --- a/src/Recyclarr.TrashLib/ApiServices/System/ServiceInformation.cs +++ b/src/Recyclarr.TrashLib/ApiServices/System/ServiceInformation.cs @@ -1,6 +1,5 @@ using Flurl.Http; using Recyclarr.TrashLib.Config.Services; -using Recyclarr.TrashLib.Http; namespace Recyclarr.TrashLib.ApiServices.System; @@ -15,7 +14,7 @@ public class ServiceInformation : IServiceInformation _log = log; } - public async Task GetVersion(IServiceConfiguration config) + public async Task GetVersion(IServiceConfiguration config) { try { @@ -23,11 +22,10 @@ public class ServiceInformation : IServiceInformation _log.Debug("{Service} Version: {Version}", status.AppName, status.Version); return new Version(status.Version); } - catch (FlurlHttpException ex) + catch (FlurlHttpException) { - _log.Error("Exception trying to obtain service version: {Message}", ex.SanitizedExceptionMessage()); + _log.Error("Unable to obtain service version information"); + throw; } - - return null; } } diff --git a/src/Recyclarr.TrashLib/Compatibility/Radarr/IRadarrCapabilityFetcher.cs b/src/Recyclarr.TrashLib/Compatibility/Radarr/IRadarrCapabilityFetcher.cs index 1638866b..6c473863 100644 --- a/src/Recyclarr.TrashLib/Compatibility/Radarr/IRadarrCapabilityFetcher.cs +++ b/src/Recyclarr.TrashLib/Compatibility/Radarr/IRadarrCapabilityFetcher.cs @@ -4,5 +4,5 @@ namespace Recyclarr.TrashLib.Compatibility.Radarr; public interface IRadarrCapabilityFetcher { - Task GetCapabilities(IServiceConfiguration config); + Task GetCapabilities(IServiceConfiguration config); } diff --git a/src/Recyclarr.TrashLib/Compatibility/Radarr/RadarrCapabilityEnforcer.cs b/src/Recyclarr.TrashLib/Compatibility/Radarr/RadarrCapabilityEnforcer.cs index d6551027..326db829 100644 --- a/src/Recyclarr.TrashLib/Compatibility/Radarr/RadarrCapabilityEnforcer.cs +++ b/src/Recyclarr.TrashLib/Compatibility/Radarr/RadarrCapabilityEnforcer.cs @@ -1,5 +1,4 @@ using Recyclarr.TrashLib.Config.Services; -using Recyclarr.TrashLib.ExceptionTypes; namespace Recyclarr.TrashLib.Compatibility.Radarr; @@ -14,11 +13,7 @@ public class RadarrCapabilityEnforcer public async Task Check(RadarrConfiguration config) { - var capabilities = await _capabilityFetcher.GetCapabilities(config); - if (capabilities is null) - { - throw new ServiceIncompatibilityException("Capabilities could not be obtained"); - } + _ = await _capabilityFetcher.GetCapabilities(config); // For the future: Add more capability checks here as needed } diff --git a/src/Recyclarr.TrashLib/Compatibility/ServiceCapabilityFetcher.cs b/src/Recyclarr.TrashLib/Compatibility/ServiceCapabilityFetcher.cs index 7b03333a..a29a32c6 100644 --- a/src/Recyclarr.TrashLib/Compatibility/ServiceCapabilityFetcher.cs +++ b/src/Recyclarr.TrashLib/Compatibility/ServiceCapabilityFetcher.cs @@ -12,10 +12,10 @@ public abstract class ServiceCapabilityFetcher where T : class _info = info; } - public async Task GetCapabilities(IServiceConfiguration config) + public async Task GetCapabilities(IServiceConfiguration config) { var version = await _info.GetVersion(config); - return version is not null ? BuildCapabilitiesObject(version) : null; + return BuildCapabilitiesObject(version); } protected abstract T BuildCapabilitiesObject(Version version); diff --git a/src/Recyclarr.TrashLib/Compatibility/Sonarr/ISonarrCapabilityFetcher.cs b/src/Recyclarr.TrashLib/Compatibility/Sonarr/ISonarrCapabilityFetcher.cs index f5a4bb72..3bbe8e8e 100644 --- a/src/Recyclarr.TrashLib/Compatibility/Sonarr/ISonarrCapabilityFetcher.cs +++ b/src/Recyclarr.TrashLib/Compatibility/Sonarr/ISonarrCapabilityFetcher.cs @@ -4,5 +4,5 @@ namespace Recyclarr.TrashLib.Compatibility.Sonarr; public interface ISonarrCapabilityFetcher { - Task GetCapabilities(IServiceConfiguration config); + Task GetCapabilities(IServiceConfiguration config); } diff --git a/src/Recyclarr.TrashLib/Compatibility/Sonarr/SonarrCapabilityEnforcer.cs b/src/Recyclarr.TrashLib/Compatibility/Sonarr/SonarrCapabilityEnforcer.cs index cf824539..fbf91587 100644 --- a/src/Recyclarr.TrashLib/Compatibility/Sonarr/SonarrCapabilityEnforcer.cs +++ b/src/Recyclarr.TrashLib/Compatibility/Sonarr/SonarrCapabilityEnforcer.cs @@ -16,10 +16,6 @@ public class SonarrCapabilityEnforcer public async Task Check(SonarrConfiguration config) { var capabilities = await _capabilityFetcher.GetCapabilities(config); - if (capabilities is null) - { - throw new ServiceIncompatibilityException("Capabilities could not be obtained"); - } if (!capabilities.SupportsNamedReleaseProfiles) { diff --git a/src/tests/Recyclarr.TrashLib.Tests/Compatibility/Sonarr/SonarrCapabilityEnforcerTest.cs b/src/tests/Recyclarr.TrashLib.Tests/Compatibility/Sonarr/SonarrCapabilityEnforcerTest.cs index b9538a9a..4531c914 100644 --- a/src/tests/Recyclarr.TrashLib.Tests/Compatibility/Sonarr/SonarrCapabilityEnforcerTest.cs +++ b/src/tests/Recyclarr.TrashLib.Tests/Compatibility/Sonarr/SonarrCapabilityEnforcerTest.cs @@ -9,20 +9,6 @@ namespace Recyclarr.TrashLib.Tests.Compatibility.Sonarr; [Parallelizable(ParallelScope.All)] public class SonarrCapabilityEnforcerTest { - [Test, AutoMockData] - public void Fail_when_capabilities_not_obtained( - [Frozen] ISonarrCapabilityFetcher fetcher, - SonarrCapabilityEnforcer sut) - { - var config = NewConfig.Sonarr(); - - fetcher.GetCapabilities(default!).ReturnsForAnyArgs((SonarrCapabilities?) null); - - var act = () => sut.Check(config); - - act.Should().ThrowAsync().WithMessage("*obtained*"); - } - [Test, AutoMockData] public void Minimum_version_not_met( [Frozen] ISonarrCapabilityFetcher fetcher,