From 973c86d5d2f59bd9b5b29d06d65082557e9ef807 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Thu, 29 Aug 2024 21:13:01 +0100 Subject: [PATCH 1/2] When processors are invlaid I have added better merror messages. --- src/MigrationTools/MigrationTools.csproj | 4 ---- .../InvalidProcessorException.cs | 20 +++++++++++++++++++ .../ProcessorContainerOptions.cs | 6 +++--- 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 src/MigrationTools/Processors/Infrastructure/InvalidProcessorException.cs diff --git a/src/MigrationTools/MigrationTools.csproj b/src/MigrationTools/MigrationTools.csproj index c345959d9..cdd2da946 100644 --- a/src/MigrationTools/MigrationTools.csproj +++ b/src/MigrationTools/MigrationTools.csproj @@ -64,8 +64,4 @@ - - - - diff --git a/src/MigrationTools/Processors/Infrastructure/InvalidProcessorException.cs b/src/MigrationTools/Processors/Infrastructure/InvalidProcessorException.cs new file mode 100644 index 000000000..27831aff2 --- /dev/null +++ b/src/MigrationTools/Processors/Infrastructure/InvalidProcessorException.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MigrationTools.Processors.Infrastructure +{ + public class InvalidProcessorException : Exception + { + + public InvalidProcessorException() : base() + { + } + public InvalidProcessorException(string message) : base(message) + { + } + public InvalidProcessorException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/src/MigrationTools/Processors/Infrastructure/ProcessorContainerOptions.cs b/src/MigrationTools/Processors/Infrastructure/ProcessorContainerOptions.cs index df64fe21c..1fdb2e0ec 100644 --- a/src/MigrationTools/Processors/Infrastructure/ProcessorContainerOptions.cs +++ b/src/MigrationTools/Processors/Infrastructure/ProcessorContainerOptions.cs @@ -41,13 +41,13 @@ private void BindProcessorOptions(ProcessorContainerOptions options, string sect if (processorTypeString == null) { Log.Warning("There was no value for {optionTypeName} from {sectionKey}", objectTypePropertyName, processorSection.Key); - throw new Exception(); + throw new InvalidProcessorException($"Your processor at `{processorSection.Path}` in the config does not have a property called {objectTypePropertyName} that is required to sucessfully detect the type and load it. "); } var processorType = AppDomain.CurrentDomain.GetMigrationToolsTypes().WithInterface().WithNameString(processorTypeString); if (processorType == null) { - Log.Warning("There was no match for {optionTypeName} from {sectionKey}", objectTypePropertyName, processorSection.Key); - throw new Exception(); + Log.Warning($"The value of {objectTypePropertyName} for your processor at `{processorSection.Path}` may have an error as were were unable to find a type that matches {processorTypeString}! Please check the spelling, and that its a processor listed in the documentation."); + throw new InvalidProcessorException(); } IProcessorOptions processorOption = Activator.CreateInstance(processorType) as IProcessorOptions; From b045a9a577fddc6ec28e9c141b7220f724b1160e Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Thu, 29 Aug 2024 21:33:34 +0100 Subject: [PATCH 2/2] Update the erro messages again to be way better. --- docs/Reference/Generated/MigrationTools.xml | 20 +++++++++---------- .../Commands/ExecuteMigrationCommand.cs | 1 + src/MigrationTools.Host/MigrationToolHost.cs | 7 +++++-- .../ProcessorContainerOptions.cs | 15 +++++++++----- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/docs/Reference/Generated/MigrationTools.xml b/docs/Reference/Generated/MigrationTools.xml index 261b37334..f5caf8757 100644 --- a/docs/Reference/Generated/MigrationTools.xml +++ b/docs/Reference/Generated/MigrationTools.xml @@ -258,37 +258,37 @@ - => @"topic/rename-project-folders" + => @"topic/docs-erros-more" - => @"36ca50a9" + => @"973c86d5" - => @"36ca50a9e89722b4b51bfb95768da82a35b59a0f" + => @"973c86d5d2f59bd9b5b29d06d65082557e9ef807" - => @"2024-08-29T15:31:58+01:00" + => @"2024-08-29T21:13:01+01:00" - => @"7" + => @"1" - => @"v16.0.0-Preview.2-7-g36ca50a9" + => @"v16.0.0-Preview.3-1-g973c86d5" - => @"v16.0.0-Preview.2" + => @"v16.0.0-Preview.3" @@ -318,17 +318,17 @@ - => @"7" + => @"1" - => @"Preview.2" + => @"Preview.3" - => @"-Preview.2" + => @"-Preview.3" diff --git a/src/MigrationTools.Host/Commands/ExecuteMigrationCommand.cs b/src/MigrationTools.Host/Commands/ExecuteMigrationCommand.cs index 711280cce..776ea54bf 100644 --- a/src/MigrationTools.Host/Commands/ExecuteMigrationCommand.cs +++ b/src/MigrationTools.Host/Commands/ExecuteMigrationCommand.cs @@ -41,6 +41,7 @@ internal override async Task ExecuteInternalAsync(CommandContext context, E { Telemetery.TrackException(ex, null, null); _logger.LogError(ex, "Unhandled exception!"); + _exitCode = 1; } finally diff --git a/src/MigrationTools.Host/MigrationToolHost.cs b/src/MigrationTools.Host/MigrationToolHost.cs index ce27951d3..b2804bc5d 100644 --- a/src/MigrationTools.Host/MigrationToolHost.cs +++ b/src/MigrationTools.Host/MigrationToolHost.cs @@ -139,9 +139,12 @@ public static IHostBuilder CreateDefaultBuilder(string[] args, Action + { + configureOptions.SuppressStatusMessages = true; + } ); + return hostBuilder; } diff --git a/src/MigrationTools/Processors/Infrastructure/ProcessorContainerOptions.cs b/src/MigrationTools/Processors/Infrastructure/ProcessorContainerOptions.cs index 1fdb2e0ec..44c21dad3 100644 --- a/src/MigrationTools/Processors/Infrastructure/ProcessorContainerOptions.cs +++ b/src/MigrationTools/Processors/Infrastructure/ProcessorContainerOptions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Configuration; +using System.Linq; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; using MigrationTools._EngineV1.Configuration; @@ -34,20 +35,24 @@ public void Configure(ProcessorContainerOptions options) private void BindProcessorOptions(ProcessorContainerOptions options, string sectionName, string objectTypePropertyName) { _configuration.GetSection(sectionName).Bind(options); + var validProcessors = AppDomain.CurrentDomain.GetMigrationToolsTypes().WithInterface(); foreach (var processorSection in _configuration.GetSection(sectionName).GetChildren()) { var processorTypeString = processorSection.GetValue(objectTypePropertyName); if (processorTypeString == null) { - Log.Warning("There was no value for {optionTypeName} from {sectionKey}", objectTypePropertyName, processorSection.Key); - throw new InvalidProcessorException($"Your processor at `{processorSection.Path}` in the config does not have a property called {objectTypePropertyName} that is required to sucessfully detect the type and load it. "); + Log.Fatal("Your processor at `{path}` in the config does not have a property called {objectTypePropertyName} that is required to sucessfully detect the type and load it. ", processorSection.Path, objectTypePropertyName); + throw new InvalidProcessorException($"`{objectTypePropertyName}` missing"); } - var processorType = AppDomain.CurrentDomain.GetMigrationToolsTypes().WithInterface().WithNameString(processorTypeString); + + + var processorType = validProcessors.WithNameString(processorTypeString); if (processorType == null) { - Log.Warning($"The value of {objectTypePropertyName} for your processor at `{processorSection.Path}` may have an error as were were unable to find a type that matches {processorTypeString}! Please check the spelling, and that its a processor listed in the documentation."); - throw new InvalidProcessorException(); + Log.Fatal("The value of {objectTypePropertyName} for your processor at `{path}` may have an error as were were unable to find a type that matches {processorTypeString}! Please check the spelling, and that its a processor listed in the documentation.", objectTypePropertyName, processorSection.Path, processorTypeString); + Log.Information("Valid options are @{validProcessors}", validProcessors.Select(type => type.Name).ToList()); + throw new InvalidProcessorException($"`{processorTypeString}` is not valid"); } IProcessorOptions processorOption = Activator.CreateInstance(processorType) as IProcessorOptions;