Improve error messaging for not finding JSON selectors in Cardigann

This commit is contained in:
Bogdan
2025-04-21 14:36:35 +03:00
parent 0b3a5c9bc4
commit 48a658571b
2 changed files with 8 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using AngleSharp.Dom; using AngleSharp.Dom;
using Microsoft.AspNetCore.WebUtilities; using Microsoft.AspNetCore.WebUtilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NLog; using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
@@ -214,19 +215,19 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
if (selector.Selector != null) if (selector.Selector != null)
{ {
var selectorSelector = ApplyGoTemplateText(selector.Selector.TrimStart('.'), variables); var selectorSelector = ApplyGoTemplateText(selector.Selector.TrimStart('.'), variables);
selectorSelector = JsonParseFieldSelector(parentObj, selectorSelector); var fieldSelector = JsonParseFieldSelector(parentObj, selectorSelector);
JToken selection = null; JToken selection = null;
if (selectorSelector != null) if (fieldSelector != null)
{ {
selection = parentObj.SelectToken(selectorSelector); selection = parentObj.SelectToken(fieldSelector);
} }
if (selection == null) if (selection == null)
{ {
if (required) if (required)
{ {
throw new Exception(string.Format("Selector \"{0}\" didn't match {1}", selectorSelector, parentObj.ToString())); throw new Exception($"Selector \"{selectorSelector}\" didn't match {parentObj.ToString(Formatting.None)}");
} }
return null; return null;
@@ -234,7 +235,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
if (selection.Type is JTokenType.Array) if (selection.Type is JTokenType.Array)
{ {
// turn this json array into a comma delimited string // turn this json array into a comma-delimited string
var valueArray = selection.Value<JArray>(); var valueArray = selection.Value<JArray>();
value = string.Join(",", valueArray); value = string.Join(",", valueArray);
} }
@@ -259,7 +260,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
{ {
if (required) if (required)
{ {
throw new Exception($"None of the case selectors \"{string.Join(",", selector.Case)}\" matched {parentObj}"); throw new Exception($"None of the case selectors \"{string.Join(",", selector.Case)}\" matched {parentObj.ToString(Formatting.None)}");
} }
return null; return null;

View File

@@ -105,7 +105,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.Trace(ex, "Failed to parse JSON rows count."); _logger.Debug(ex, "Failed to parse JSON rows count.");
} }
} }