Throw exception on unexpected failure of creation on enum value from configuration, rather than falling back to a default.

This shouldn't happen in practice due to the configuration validation (e.g. by ContentSettingsValidator), so any failure of parsing here should be considered an exception.
This commit is contained in:
Andy Butland
2020-09-21 12:04:30 +02:00
parent e032af5b06
commit cce091de74
4 changed files with 16 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Configuration.Models.Validation;
using Umbraco.Core.Macros;
namespace Umbraco.Core.Configuration.Models
@@ -31,7 +32,9 @@ namespace Umbraco.Core.Configuration.Models
{
return Enum.TryParse<MacroErrorBehaviour>(MacroErrors, true, out var value)
? value
: MacroErrorBehaviour.Inline;
: 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)}.");
}
}

View File

@@ -1,4 +1,5 @@
using System;
using Umbraco.Core.Configuration.Models.Validation;
namespace Umbraco.Core.Configuration.Models
{
@@ -18,7 +19,9 @@ namespace Umbraco.Core.Configuration.Models
{
return Enum.TryParse<LocalTempStorage>(LocalTempStorageLocation, true, out var value)
? value
: LocalTempStorage.Default;
: 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)}.");
}
}

View File

@@ -1,5 +1,6 @@
using System;
using Umbraco.Configuration;
using Umbraco.Core.Configuration.Models.Validation;
namespace Umbraco.Core.Configuration.Models
{
@@ -31,7 +32,9 @@ namespace Umbraco.Core.Configuration.Models
{
return Enum.TryParse<ModelsMode>(ModelsMode, true, out var value)
? value
: Configuration.ModelsMode.Nothing;
: 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)}.");
}
}

View File

@@ -26,7 +26,10 @@ namespace Umbraco.Core.Configuration.Models
{
return Enum.TryParse<SmtpDeliveryMethod>(DeliveryMethod, true, out var value)
? value
: SmtpDeliveryMethod.Network;
: 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)}.");
}
}