From 66a0ad17aadc602995587cd76eef043446fd04fa Mon Sep 17 00:00:00 2001 From: Anthony Truskinger Date: Wed, 16 Dec 2020 14:38:32 +1000 Subject: [PATCH] Adds a friendly error msg when config file is empty Also makes high res indices option for recogniser base optional through a default value --- src/Acoustics.Shared/ConfigFile/ConfigFile.Deserialize.cs | 5 +++++ src/AnalysisPrograms/Recognizers/Base/RecognizerBase.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Acoustics.Shared/ConfigFile/ConfigFile.Deserialize.cs b/src/Acoustics.Shared/ConfigFile/ConfigFile.Deserialize.cs index a1bb42094..cfad7a644 100644 --- a/src/Acoustics.Shared/ConfigFile/ConfigFile.Deserialize.cs +++ b/src/Acoustics.Shared/ConfigFile/ConfigFile.Deserialize.cs @@ -120,6 +120,11 @@ private static T LoadAndCache(string path, Func factory) (generic, loadedConfig) = Yaml.LoadAndDeserialize(path); } + if (loadedConfig is null) + { + throw new ConfigFileException($"Tried to load the {path} config file but it looks like it was empty. Add some content?", path); + } + // if implements Config in any subtype (more specific than IConfig) if (loadedConfig is Config config) { diff --git a/src/AnalysisPrograms/Recognizers/Base/RecognizerBase.cs b/src/AnalysisPrograms/Recognizers/Base/RecognizerBase.cs index dd54d6412..c2bebe6fc 100644 --- a/src/AnalysisPrograms/Recognizers/Base/RecognizerBase.cs +++ b/src/AnalysisPrograms/Recognizers/Base/RecognizerBase.cs @@ -444,7 +444,7 @@ public RecognizerConfig() }; } - public string HighResolutionIndicesConfig { get; set; } + public string HighResolutionIndicesConfig { get; set; } = "Towsey.Acoustic.HiResIndicesForRecognisers.yml"; public AcousticIndices.AcousticIndicesConfig HighResolutionIndices { get; private set; } }