refactor: Address a few more SonarLint issues

pull/259/head
Robert Dailey 4 months ago
parent cb56ab5737
commit 4388515614

@ -31,19 +31,14 @@ public class TemplateConfigCreator(
{
CopyTemplate(templateFile, settings);
}
catch (FileExistsException e)
{
log.Error(e, "Template configuration file could not be saved");
}
catch (FileLoadException)
{
// Do not log here since the origin of this exception is ConfigParser.Load(), which already has
// sufficient logging.
}
catch (Exception e)
catch (IOException e)
{
log.Error(e, "Unable to save configuration template file");
throw;
log.Error(e, "Unable to save configuration template file; skipping");
}
}
}

@ -4,6 +4,7 @@ using Recyclarr.Compatibility;
using Recyclarr.Config.ExceptionTypes;
using Recyclarr.Config.Parsing.ErrorHandling;
using Recyclarr.VersionControl;
using YamlDotNet.Core;
namespace Recyclarr.Cli.Processors.ErrorHandling;
@ -59,6 +60,15 @@ public class ConsoleExceptionHandler(ILogger log, IFlurlHttpExceptionHandler htt
log.Error(e.Message);
break;
case YamlException e:
log.Error(e, "Exception while parsing settings.yml at line {Line}", e.Start.Line);
if (e.Data["ContextualMessage"] is string context)
{
log.Error(context);
}
break;
default:
return false;
}

@ -8,7 +8,7 @@ namespace Recyclarr.Cli;
internal static class Program
{
public static int Main(string[] args)
public static async Task<int> Main(string[] args)
{
var builder = new ContainerBuilder();
CompositionRoot.Setup(builder);
@ -43,6 +43,6 @@ internal static class Program
CliSetup.Commands(config);
});
return app.Run(args);
return await app.RunAsync(args);
}
}

@ -2,22 +2,19 @@ using System.IO.Abstractions;
using Recyclarr.Common.Extensions;
using Recyclarr.Platform;
using Recyclarr.Yaml;
using Serilog;
using YamlDotNet.Core;
namespace Recyclarr.Settings;
public class SettingsProvider : ISettingsProvider
{
private readonly ILogger _log;
private readonly IAppPaths _paths;
private readonly Lazy<SettingsValues> _settings;
public SettingsValues Settings => _settings.Value;
public SettingsProvider(ILogger log, IAppPaths paths, IYamlSerializerFactory serializerFactory)
public SettingsProvider(IAppPaths paths, IYamlSerializerFactory serializerFactory)
{
_log = log;
_paths = paths;
_settings = new Lazy<SettingsValues>(() => LoadOrCreateSettingsFile(serializerFactory));
}
@ -34,14 +31,7 @@ public class SettingsProvider : ISettingsProvider
}
catch (YamlException e)
{
_log.Error(e, "Exception while parsing settings.yml at line {Line}", e.Start.Line);
var context = SettingsContextualMessages.GetContextualErrorFromException(e);
if (context is not null)
{
_log.Error(context);
}
e.Data["ContextualMessage"] = SettingsContextualMessages.GetContextualErrorFromException(e);
throw;
}
}

@ -54,7 +54,7 @@ internal class BaseCommandSetupIntegrationTest : CliIntegrationFixture
var sut = Resolve<JanitorCleanupTask>();
sut.OnFinish();
maxFiles.Should().BeGreaterThan(0);
maxFiles.Should().BePositive();
Fs.AllFiles.Where(x => x.StartsWith(Paths.LogDirectory.FullName))
.Should().HaveCount(maxFiles);
}

@ -27,7 +27,7 @@ public class DictionaryExtensionsTest
var theValue = dict.GetValueOrDefault(200);
dict.Should().HaveCount(1).And.Contain(100, sample);
dict.Should().ContainSingle().And.Contain(100, sample);
theValue.Should().BeNull();
}

Loading…
Cancel
Save