From 07fca003449dafeadf3137bf1db5be5fe56fd989 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 10 Dec 2025 14:54:20 +0100 Subject: [PATCH] Replace InvalidOperationException with custom config exception Refactored DbModelOptions and EntityBaseOptions to throw DbModelConfigurationException instead of InvalidOperationException for configuration errors. Added necessary using directives for the new exception type to improve error clarity and specificity. --- src/ReC.Infrastructure/Options/DbModelOptions.cs | 5 +++-- src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ReC.Infrastructure/Options/DbModelOptions.cs b/src/ReC.Infrastructure/Options/DbModelOptions.cs index 4cde16a..1a8ac29 100644 --- a/src/ReC.Infrastructure/Options/DbModelOptions.cs +++ b/src/ReC.Infrastructure/Options/DbModelOptions.cs @@ -1,4 +1,5 @@ -using ReC.Infrastructure.Options.Shared; +using ReC.Infrastructure.Exceptions; +using ReC.Infrastructure.Options.Shared; namespace ReC.Infrastructure.Options; @@ -18,6 +19,6 @@ public record DbModelOptions if(cluster.TryGetValue(nameof(T), out var entityOptions)) entityOptions.EnsureProperties(); else - throw new InvalidOperationException($"Entity options for type '{typeof(T).FullName}' not found."); + throw new DbModelConfigurationException($"Entity options for type '{typeof(T).FullName}' not found."); } } diff --git a/src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs b/src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs index fa9d890..395e367 100644 --- a/src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs +++ b/src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs @@ -1,4 +1,5 @@ using ReC.Domain.Attributes; +using ReC.Infrastructure.Exceptions; namespace ReC.Infrastructure.Options.Shared; @@ -15,7 +16,7 @@ public record EntityBaseOptions() var missingProperties = propertyNames.Except(PropertyNames).ToList(); if (missingProperties.Count != 0) - throw new InvalidOperationException($"The following properties are not configured: {string.Join(", ", missingProperties)}"); + throw new DbModelConfigurationException($"The following properties are not configured: {string.Join(", ", missingProperties)}"); } public void EnsureProperties(params string[] propertyNames)