Reverted change to enum parse from string configuration value, as we can't avoid the property being evaluated before the validation has occurred.

This commit is contained in:
Andy Butland
2020-09-21 16:23:58 +02:00
parent 1a59d6a978
commit 574e4d6446
4 changed files with 35 additions and 20 deletions

View File

@@ -30,11 +30,15 @@ namespace Umbraco.Core.Configuration.Models
{
get
{
return Enum.TryParse<MacroErrorBehaviour>(MacroErrors, true, out var value)
? value
: throw new InvalidOperationException(
$"Parsing of {nameof(MacroErrors)} field value of {MacroErrors} was not recognised as a valid value of the enum {nameof(MacroErrorBehaviour)}. " +
$"This state shouldn't have been reached as if the configuration contains an invalid valie it should be caught by {nameof(ContentSettingsValidator)}.");
if (Enum.TryParse<MacroErrorBehaviour>(MacroErrors, true, out var value))
{
return value;
}
// We need to return somethhing valid here as this property is evalulated during start-up, and if there's an error
// in the configured value it won't be parsed to the enum.
// At run-time though this default won't be used, as an invalid value will be picked up by ContentSettingsValidator.
return MacroErrorBehaviour.Inline;
}
}

View File

@@ -17,11 +17,15 @@ namespace Umbraco.Core.Configuration.Models
{
get
{
return Enum.TryParse<LocalTempStorage>(LocalTempStorageLocation, true, out var value)
? value
: throw new InvalidOperationException(
$"Parsing of {nameof(LocalTempStorageLocation)} field value of {LocalTempStorageLocation} was not recognised as a valid value of the enum {nameof(LocalTempStorage)}. " +
$"This state shouldn't have been reached as if the configuration contains an invalid valie it should be caught by {nameof(HostingSettingsValidator)}.");
if (Enum.TryParse<LocalTempStorage>(LocalTempStorageLocation, true, out var value))
{
return value;
}
// We need to return somethhing valid here as this property is evalulated during start-up, and if there's an error
// in the configured value it won't be parsed to the enum.
// At run-time though this default won't be used, as an invalid value will be picked up by HostingSettingsValidator.
return LocalTempStorage.Default;
}
}

View File

@@ -30,11 +30,15 @@ namespace Umbraco.Core.Configuration.Models
{
get
{
return Enum.TryParse<ModelsMode>(ModelsMode, true, out var value)
? value
: throw new InvalidOperationException(
$"Parsing of {nameof(ModelsMode)} field value of {ModelsMode} was not recognised as a valid value of the enum {nameof(ModelsMode)}. " +
$"This state shouldn't have been reached as if the configuration contains an invalid valie it should be caught by {nameof(ModelsBuilderSettingsValidator)}.");
if (Enum.TryParse<ModelsMode>(ModelsMode, true, out var value))
{
return value;
}
// We need to return somethhing valid here as this property is evalulated during start-up, and if there's an error
// in the configured value it won't be parsed to the enum.
// At run-time though this default won't be used, as an invalid value will be picked up by ModelsBuilderSettingsValidator.
return Configuration.ModelsMode.Nothing;
}
}

View File

@@ -24,12 +24,15 @@ namespace Umbraco.Core.Configuration.Models
{
get
{
return Enum.TryParse<SmtpDeliveryMethod>(DeliveryMethod, true, out var value)
? value
: throw new InvalidOperationException(
$"Parsing of {nameof(DeliveryMethod)} field value of {DeliveryMethod} was not recognised as a valid value of the enum {nameof(SmtpDeliveryMethod)}. " +
$"This state shouldn't have been reached as if the configuration contains an invalid valie it should be caught by {nameof(GlobalSettingsValidator)}.");
if (Enum.TryParse<SmtpDeliveryMethod>(DeliveryMethod, true, out var value))
{
return value;
}
// We need to return somethhing valid here as this property is evalulated during start-up, and if there's an error
// in the configured value it won't be parsed to the enum.
// At run-time though this default won't be used, as an invalid value will be picked up by GlobalSettingsValidator.
return SmtpDeliveryMethod.Network;
}
}