From 4280df8b61ff8adf1b58b3229750b520dffc0276 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 17 Oct 2022 22:50:43 -0500 Subject: [PATCH] Fixed: Better error messaging if you try to import an invalid Custom Format Co-Authored-By: Robert Dailey <1768054+rcdailey@users.noreply.github.com> --- .../CustomFormats/CustomFormatResource.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Radarr.Api.V3/CustomFormats/CustomFormatResource.cs b/src/Radarr.Api.V3/CustomFormats/CustomFormatResource.cs index 2cfcedca2..bfa9563b6 100644 --- a/src/Radarr.Api.V3/CustomFormats/CustomFormatResource.cs +++ b/src/Radarr.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,15 @@ namespace Radarr.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(); var spec = (ICustomFormatSpecification)SchemaBuilder.ReadFromSchema(resource.Fields, type); spec.Name = resource.Name; spec.Negate = resource.Negate;