From 51eeb4ee0fec3d12b822533dbbe4103248c194e0 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Thu, 22 Sep 2022 11:44:45 -0500 Subject: [PATCH] Fixed: Better error messaging if you try to import an invalid Custom Format --- .../CustomFormats/CustomFormatResource.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Sonarr.Api.V3/CustomFormats/CustomFormatResource.cs b/src/Sonarr.Api.V3/CustomFormats/CustomFormatResource.cs index c8870aa7e..e004f2a7f 100644 --- a/src/Sonarr.Api.V3/CustomFormats/CustomFormatResource.cs +++ b/src/Sonarr.Api.V3/CustomFormats/CustomFormatResource.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; @@ -47,7 +48,16 @@ namespace Sonarr.Api.V3.CustomFormats private static ICustomFormatSpecification MapSpecification(CustomFormatSpecificationSchema resource, List specifications) { - var type = specifications.SingleOrDefault(x => x.GetType().Name == resource.Implementation).GetType(); + var matchingSpec = + specifications.SingleOrDefault(x => x.GetType().Name == resource.Implementation); + + if (matchingSpec is null) + { + throw new ArgumentException( + $"{resource.Implementation} is not a valid specification implementation"); + } + + var type = matchingSpec.GetType(); // Finding the exact current specification isn't possible given the dynamic nature of them and the possibility that multiple // of the same type exist within the same format. Passing in null is safe as long as there never exists a specification that