refactor!: Remove old reset_unmatched_scores syntax support

Relates to #202
json-serializing-nullable-fields-issue
Robert Dailey 8 months ago
parent 1bbafa6386
commit 5c7cc8d829

@ -17,6 +17,7 @@ changes you may need to make.
- **BREAKING**: Minimum required Sonarr version increased to `3.0.9.1549` (Previous minimum version - **BREAKING**: Minimum required Sonarr version increased to `3.0.9.1549` (Previous minimum version
was `3.0.4.1098`). was `3.0.4.1098`).
- **BREAKING**: Old boolean syntax for `reset_unmatched_scores` is no longer supported.
## [5.4.3] - 2023-09-16 ## [5.4.3] - 2023-09-16

@ -47,18 +47,25 @@ public class ConfigParser
_log.Debug(e, "Exception while parsing config file"); _log.Debug(e, "Exception while parsing config file");
var line = e.Start.Line; var line = e.Start.Line;
switch (e.InnerException)
var contextualMsg = ConfigContextualMessages.GetContextualErrorFromException(e);
if (contextualMsg is not null)
{
_log.Error("Exception at line {Line}: {Msg}", line, contextualMsg);
}
else
{ {
case InvalidCastException: switch (e.InnerException)
_log.Error("Incompatible value assigned/used at line {Line}: {Msg}", line, {
e.InnerException.Message); case InvalidCastException:
break; _log.Error("Incompatible value assigned/used at line {Line}: {Msg}", line,
e.InnerException.Message);
break;
default: default:
var msg = ConfigContextualMessages.GetContextualErrorFromException(e) ?? _log.Error("Exception at line {Line}: {Msg}", line, e.InnerException?.Message ?? e.Message);
e.InnerException?.Message ?? e.Message; break;
_log.Error("Exception at line {Line}: {Msg}", line, msg); }
break;
} }
} }

@ -1,7 +1,5 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations; using JetBrains.Annotations;
using Recyclarr.TrashLib.Config.Parsing.BackwardCompatibility;
using Recyclarr.TrashLib.Config.Parsing.PostProcessing.ConfigMerging; using Recyclarr.TrashLib.Config.Parsing.PostProcessing.ConfigMerging;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
@ -45,13 +43,8 @@ public record QualityProfileQualityConfigYaml
} }
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
[TypeConverter(typeof(ResetUnmatchedScoresYamlTypeConverter))]
public record ResetUnmatchedScoresConfigYaml public record ResetUnmatchedScoresConfigYaml
{ {
// This exists so that we know if this value came from the legacy 'true|false' value.
[YamlIgnore]
public bool FromBool { get; set; }
public bool? Enabled { get; init; } public bool? Enabled { get; init; }
public IReadOnlyCollection<string>? Except { get; init; } public IReadOnlyCollection<string>? Except { get; init; }
} }

@ -93,13 +93,6 @@ public class ResetUnmatchedScoresConfigYamlValidator : AbstractValidator<ResetUn
RuleFor(x => x.Enabled) RuleFor(x => x.Enabled)
.NotNull() .NotNull()
.WithMessage("Under `reset_unmatched_scores`, the `enabled` property is required."); .WithMessage("Under `reset_unmatched_scores`, the `enabled` property is required.");
RuleFor(x => x.FromBool)
.Must(x => !x) // must be false
.WithMessage(
"Using true/false with `reset_unmatched_scores` is deprecated. " +
"See: https://recyclarr.dev/wiki/upgrade-guide/v6.0/#reset-scores")
.WithSeverity(Severity.Warning);
} }
} }

@ -6,7 +6,17 @@ public static class ConfigContextualMessages
{ {
public static string? GetContextualErrorFromException(YamlException e) public static string? GetContextualErrorFromException(YamlException e)
{ {
if (e.Message.Contains( return LookupMessage(e.Message) ?? LookupMessage(e.InnerException?.Message);
}
private static string? LookupMessage(string? msg)
{
if (msg is null)
{
return null;
}
if (msg.Contains(
"Property 'reset_unmatched_scores' not found on type " + "Property 'reset_unmatched_scores' not found on type " +
$"'{typeof(QualityScoreConfigYaml).FullName}'")) $"'{typeof(QualityScoreConfigYaml).FullName}'"))
{ {
@ -16,6 +26,14 @@ public static class ConfigContextualMessages
"See: https://recyclarr.dev/wiki/upgrade-guide/v5.0/#reset-unmatched-scores"; "See: https://recyclarr.dev/wiki/upgrade-guide/v5.0/#reset-unmatched-scores";
} }
if (msg.Contains(
$"Invalid cast from 'System.String' to '{typeof(ResetUnmatchedScoresConfigYaml).FullName}'"))
{
return
"Using true/false with `reset_unmatched_scores` is no longer supported. " +
"See: https://recyclarr.dev/wiki/upgrade-guide/v6.0/#reset-scores";
}
return null; return null;
} }
} }

@ -6,7 +6,17 @@ public static class SettingsContextualMessages
{ {
public static string? GetContextualErrorFromException(YamlException e) public static string? GetContextualErrorFromException(YamlException e)
{ {
if (e.Message.Contains( return LookupMessage(e.Message) ?? LookupMessage(e.InnerException?.Message);
}
private static string? LookupMessage(string? msg)
{
if (msg is null)
{
return null;
}
if (msg.Contains(
"Property 'repository' not found on type " + "Property 'repository' not found on type " +
$"'{typeof(SettingsValues).FullName}'")) $"'{typeof(SettingsValues).FullName}'"))
{ {

@ -40,7 +40,7 @@ public class SettingsProvider : ISettingsProvider
_log.Debug(e, "Exception while parsing settings file"); _log.Debug(e, "Exception while parsing settings file");
var line = e.Start.Line; var line = e.Start.Line;
var msg = SettingsContextualMessages.GetContextualErrorFromException(e); var msg = SettingsContextualMessages.GetContextualErrorFromException(e) ?? e.Message;
_log.Error("Exception while parsing settings.yml at line {Line}: {Msg}", line, msg); _log.Error("Exception while parsing settings.yml at line {Line}: {Msg}", line, msg);
throw; throw;

Loading…
Cancel
Save