Skip to content

Commit df545d9

Browse files
committed
🔧 (configuration.json): update project name in configuration for migration testing
The project name in the configuration file is updated from "migrationTest5" to "migrationTest55" to reflect changes in the testing environment or project structure. 📝 (MigrationTools.xml): update documentation with new commit and version details The XML documentation is updated to reflect the latest commit hash, commit date, and version tags, ensuring that the documentation is in sync with the current state of the codebase. ✨ (TfsNodeStructureTool.cs): add exception handling for project retrieval Introduces a try-catch block to handle exceptions when retrieving project information, improving robustness by catching potential configuration errors and throwing a custom `MigrationToolsException`. ✨ (MigrationToolsException.cs): create custom exception class for migration tools A new custom exception class `MigrationToolsException` is added to handle specific errors related to configuration and internal issues, providing a more structured error handling mechanism. ♻️ (Processor.cs): enhance error handling with custom exceptions Refactors the error handling in the `Processor` class to include the newly created `MigrationToolsException`, allowing for more detailed logging and error tracking based on the source of the exception. This change improves the maintainability and debuggability of the code.
1 parent 23fae28 commit df545d9

File tree

5 files changed

+73
-17
lines changed

5 files changed

+73
-17
lines changed

configuration.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"Target": {
2929
"EndpointType": "TfsTeamProjectEndpoint",
3030
"Collection": "https://dev.azure.com/nkdagility-preview/",
31-
"Project": "migrationTest5",
31+
"Project": "migrationTest55",
3232
"TfsVersion": "AzureDevOps",
3333
"Authentication": {
3434
"AuthenticationMode": "AccessToken",

docs/Reference/Generated/MigrationTools.xml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MigrationTools.Clients.TfsObjectModel/Tools/TfsNodeStructureTool.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
using Microsoft.Extensions.Logging;
99
using Microsoft.Extensions.Options;
1010
using Microsoft.TeamFoundation.Common;
11+
using Microsoft.TeamFoundation.Core.WebApi;
1112
using Microsoft.TeamFoundation.Server;
1213
using Microsoft.TeamFoundation.Work.WebApi;
1314
using MigrationTools.Clients;
1415
using MigrationTools.DataContracts;
1516
using MigrationTools.Endpoints;
1617
using MigrationTools.Enrichers;
18+
using MigrationTools.Exceptions;
1719
using MigrationTools.FieldMaps;
1820
using MigrationTools.Processors;
1921
using MigrationTools.Processors.Infrastructure;
@@ -54,13 +56,14 @@ public class TfsNodeStructureTool : Tool<TfsNodeStructureToolOptions>
5456
private TfsLanguageMapOptions _sourceLanguageMaps;
5557
private TfsLanguageMapOptions _targetLanguageMaps;
5658

57-
private ProjectInfo _sourceProjectInfo;
59+
private Microsoft.TeamFoundation.Server.ProjectInfo _sourceProjectInfo;
5860

5961
private string _sourceProjectName;
6062
private NodeInfo[] _sourceRootNodes;
6163
private ICommonStructureService4 _targetCommonStructureService;
6264

6365
private string _targetProjectName;
66+
private Microsoft.TeamFoundation.Server.ProjectInfo _targetProjectInfo;
6467
private KeyValuePair<string, string>? _lastResortRemapRule;
6568

6669
public WorkItemMetrics workItemMetrics { get; private set; }
@@ -312,6 +315,15 @@ protected void EntryForProcessorType(TfsProcessor processor)
312315
_targetCommonStructureService = processor.Target.GetService<ICommonStructureService4>();
313316
_targetLanguageMaps = processor.Target.Options.LanguageMaps;
314317
_targetProjectName = processor.Target.Options.Project;
318+
try
319+
{
320+
_targetProjectInfo = _targetCommonStructureService.GetProjectFromName(_targetProjectName);
321+
}
322+
catch (ProjectException ex)
323+
{
324+
throw new MigrationToolsException(ex, MigrationToolsException.ExceptionSource.Configuration);
325+
}
326+
315327
}
316328
}
317329
}
@@ -403,6 +415,8 @@ private static string GetUserFriendlyPath(string systemNodePath)
403415
private void MigrateAllNodeStructures()
404416
{
405417
Log.LogDebug("NodeStructureEnricher.MigrateAllNodeStructures(@{areaMaps}, @{iterationMaps})", Options.Areas, Options.Iterations);
418+
419+
406420
//////////////////////////////////////////////////
407421
ProcessCommonStructure(_sourceLanguageMaps.AreaPath, _targetLanguageMaps.AreaPath, _targetProjectName, TfsNodeStructureType.Area);
408422
//////////////////////////////////////////////////
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Elmah.Io.Client;
5+
6+
namespace MigrationTools.Exceptions
7+
{
8+
9+
10+
public class MigrationToolsException : Exception
11+
{
12+
public MigrationToolsException(Exception ex, ExceptionSource errorSource) : base(ex.Message)
13+
{
14+
this.ErrorSource = errorSource;
15+
}
16+
17+
public ExceptionSource ErrorSource { get; }
18+
19+
public enum ExceptionSource
20+
{
21+
Configuration,
22+
Internal
23+
}
24+
}
25+
}

src/MigrationTools/Processors/Infrastructure/Processor.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.Design;
34
using System.Diagnostics;
45
using System.Linq;
56
using Microsoft.Extensions.DependencyInjection;
@@ -64,13 +65,13 @@ public IEndpoint GetEndpoint(string name)
6465
{
6566
throw new ArgumentException("Endpoint name cannot be null or empty", nameof(name));
6667
}
67-
// Assuming GetRequiredKeyedService throws an exception if the service is not found
68-
IEndpoint endpoint = Services.GetKeyedService<IEndpoint>(name);
69-
if (endpoint == null)
70-
{
71-
throw new ConfigurationValidationException( Options, ValidateOptionsResult.Fail($"The Endpoint '{name}' specified for `{this.GetType().Name}` was not found."));
72-
}
73-
return endpoint;
68+
// Assuming GetRequiredKeyedService throws an exception if the service is not found
69+
IEndpoint endpoint = Services.GetKeyedService<IEndpoint>(name);
70+
if (endpoint == null)
71+
{
72+
throw new ConfigurationValidationException(Options, ValidateOptionsResult.Fail($"The Endpoint '{name}' specified for `{this.GetType().Name}` was not found."));
73+
}
74+
return endpoint;
7475
}
7576

7677
public void Execute()
@@ -113,12 +114,28 @@ public void Execute()
113114
ProcessorActivity.SetStatus(ActivityStatusCode.Error);
114115
Log.LogCritical(ex, "Validation of your configuration failed:");
115116
}
117+
catch (MigrationToolsException ex)
118+
{
119+
Status = ProcessingStatus.Failed;
120+
ProcessorActivity.SetStatus(ActivityStatusCode.Error);
121+
switch (ex.ErrorSource)
122+
{
123+
case MigrationToolsException.ExceptionSource.Configuration:
124+
Log.LogCritical(ex, "An error occurred in the Migration Tools causing it to stop! This is likley due to a configuration issue and is not being logged remotely. You can always ask on https://github.com/nkdAgility/azure-devops-migration-tools/discussions ");
125+
break;
126+
case MigrationToolsException.ExceptionSource.Internal:
127+
default:
128+
Log.LogCritical(ex, "An error occurred in the Migration Tools causing it to stop!");
129+
Telemetry.TrackException(ex, ProcessorActivity.Tags);
130+
break;
131+
}
132+
}
116133
catch (Exception ex)
117134
{
118135
Status = ProcessingStatus.Failed;
119136
ProcessorActivity.SetStatus(ActivityStatusCode.Error);
120-
Telemetry.TrackException(ex, ProcessorActivity.Tags);
121137
Log.LogCritical(ex, "Error while running {MigrationContextname}", Name);
138+
Telemetry.TrackException(ex, ProcessorActivity.Tags);
122139
}
123140
finally
124141
{

0 commit comments

Comments
 (0)