@@ -35,14 +35,14 @@ internal class ConfigSettings : IConfigSettings
3535
3636 public ConfigSettings ( Func < string , string > configSettingsGetter , Func < string , string > configPathGetter )
3737 {
38- _octopusServer = configSettingsGetter ( OctopusServerConfigName ) ;
39- _octopusApiKey = configSettingsGetter ( OctopusApiKeyConfigName ) ;
40- _tentacleEnvironment = configSettingsGetter ( TentacleEnvironmentConfigName ) ;
41- _tentacleRole = configSettingsGetter ( TentacleRoleConfigName ) ;
42- _tentacleMachineNameSuffix = configSettingsGetter ( TentacleMachineNameSuffixConfigName ) ;
43-
44- _tentacleDeploymentsPath = configPathGetter ( TentacleDeploymentsPathConfigName ) ;
45- _tentacleInstallPath = configPathGetter ( TentacleInstallPathConfigName ) ;
38+ _octopusServer = SafeGetConfigSetting ( configSettingsGetter , OctopusServerConfigName ) ;
39+ _octopusApiKey = SafeGetConfigSetting ( configSettingsGetter , OctopusApiKeyConfigName ) ;
40+ _tentacleEnvironment = SafeGetConfigSetting ( configSettingsGetter , TentacleEnvironmentConfigName ) ;
41+ _tentacleRole = SafeGetConfigSetting ( configSettingsGetter , TentacleRoleConfigName ) ;
42+ _tentacleMachineNameSuffix = SafeGetConfigSetting ( configSettingsGetter , TentacleMachineNameSuffixConfigName ) ;
43+
44+ _tentacleDeploymentsPath = SafeGetConfigSetting ( configPathGetter , TentacleDeploymentsPathConfigName ) ;
45+ _tentacleInstallPath = SafeGetConfigSetting ( configPathGetter , TentacleInstallPathConfigName ) ;
4646 }
4747
4848 public string OctopusServer { get { return _octopusServer ; } }
@@ -58,5 +58,31 @@ public bool IsConfigSettingName(string name)
5858 {
5959 return ConfigSettingsNames . Contains ( name ) ;
6060 }
61+
62+ public string SafeGetConfigSetting ( Func < string , string > configSettingsGetter , string settingName )
63+ {
64+ try
65+ {
66+ return configSettingsGetter ( settingName ) ?? "" ;
67+ }
68+ catch ( Exception e )
69+ {
70+ throw new UnableToGetConfigSettingException ( settingName , e ) ;
71+ }
72+ }
73+ }
74+
75+ /// <summary>
76+ /// Error getting a config setting.
77+ /// </summary>
78+ public class UnableToGetConfigSettingException : Exception
79+ {
80+ /// <summary>
81+ /// Create the exception for the setting in question.
82+ /// </summary>
83+ /// <param name="settingName">The name of the setting an error was raised for</param>
84+ /// <param name="exception">The exception that was raised when getting the setting</param>
85+ public UnableToGetConfigSettingException ( string settingName , Exception exception )
86+ : base ( "Unable to get config setting: " + settingName , exception ) { }
6187 }
6288}
0 commit comments