From 286f4b95b168bc2dd69603b387f83eca16573877 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sat, 29 Apr 2023 17:21:46 -0500 Subject: [PATCH] refactor: Deprecation messages for old style array mapping --- .../Config/Parsing/ConfigDeprecations.cs | 18 ++++++++++++++++++ .../Config/Parsing/ConfigParser.cs | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/Recyclarr.TrashLib/Config/Parsing/ConfigDeprecations.cs diff --git a/src/Recyclarr.TrashLib/Config/Parsing/ConfigDeprecations.cs b/src/Recyclarr.TrashLib/Config/Parsing/ConfigDeprecations.cs new file mode 100644 index 00000000..75d29911 --- /dev/null +++ b/src/Recyclarr.TrashLib/Config/Parsing/ConfigDeprecations.cs @@ -0,0 +1,18 @@ +using YamlDotNet.Core; + +namespace Recyclarr.TrashLib.Config.Parsing; + +public static class ConfigDeprecations +{ + public static string? GetContextualErrorFromException(YamlException e) + { + if (e.Message.Contains("Expected 'MappingStart', got 'SequenceStart'")) + { + return "Found array-style list of instances instead of named-style. " + + "Array-style lists of Sonarr/Radarr instances are not supported. " + + "See: https://recyclarr.dev/wiki/upgrade-guide/v5.0/#instances-must-now-be-named"; + } + + return null; + } +} diff --git a/src/Recyclarr.TrashLib/Config/Parsing/ConfigParser.cs b/src/Recyclarr.TrashLib/Config/Parsing/ConfigParser.cs index cd14d3b0..02dd3b2b 100644 --- a/src/Recyclarr.TrashLib/Config/Parsing/ConfigParser.cs +++ b/src/Recyclarr.TrashLib/Config/Parsing/ConfigParser.cs @@ -58,6 +58,8 @@ public class ConfigParser } catch (YamlException e) { + _log.Debug(e, "Exception while parsing config file"); + var line = e.Start.Line; switch (e.InnerException) { @@ -67,7 +69,11 @@ public class ConfigParser break; default: - _log.Error("Exception at line {Line}: {Msg}", line, e.InnerException?.Message ?? e.Message); + // Check for Configuration-specific deprecation messages + var msg = ConfigDeprecations.GetContextualErrorFromException(e) ?? + e.InnerException?.Message ?? e.Message; + + _log.Error("Exception at line {Line}: {Msg}", line, msg); break; }