From cce091de7485fa2b9a33d7aed4952301c0e283bd Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 21 Sep 2020 12:04:30 +0200 Subject: [PATCH] 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. --- src/Umbraco.Core/Configuration/Models/ContentSettings.cs | 5 ++++- src/Umbraco.Core/Configuration/Models/HostingSettings.cs | 5 ++++- .../Configuration/Models/ModelsBuilderSettings.cs | 5 ++++- src/Umbraco.Core/Configuration/Models/SmtpSettings.cs | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs index f58d264658..32c4cc120d 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs @@ -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(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)}."); } } diff --git a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs index 591d186761..1cd1d96e8e 100644 --- a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs @@ -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(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)}."); } } diff --git a/src/Umbraco.Core/Configuration/Models/ModelsBuilderSettings.cs b/src/Umbraco.Core/Configuration/Models/ModelsBuilderSettings.cs index 419cfd3bc9..1f0e6612df 100644 --- a/src/Umbraco.Core/Configuration/Models/ModelsBuilderSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ModelsBuilderSettings.cs @@ -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, 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)}."); } } diff --git a/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs b/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs index b7be1404c5..6ac417517f 100644 --- a/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs @@ -26,7 +26,10 @@ namespace Umbraco.Core.Configuration.Models { return Enum.TryParse(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)}."); + } }