Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor exception handling and update XML references #2419

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/Reference/Generated/MigrationTools.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.Work.WebApi;
using MigrationTools.Clients;
Expand Down Expand Up @@ -56,14 +55,13 @@ public class TfsNodeStructureTool : Tool<TfsNodeStructureToolOptions>
private TfsLanguageMapOptions _sourceLanguageMaps;
private TfsLanguageMapOptions _targetLanguageMaps;

private Microsoft.TeamFoundation.Server.ProjectInfo _sourceProjectInfo;
private ProjectInfo _sourceProjectInfo;

private string _sourceProjectName;
private NodeInfo[] _sourceRootNodes;
private ICommonStructureService4 _targetCommonStructureService;

private string _targetProjectName;
private Microsoft.TeamFoundation.Server.ProjectInfo _targetProjectInfo;
private KeyValuePair<string, string>? _lastResortRemapRule;

public WorkItemMetrics workItemMetrics { get; private set; }
Expand Down Expand Up @@ -111,7 +109,7 @@ public string GetNewNodeName(string sourceNodePath, TfsNodeStructureType nodeStr
Log.LogWarning("nodeStructureEnricher is disabled! You may get migration errors!");
return sourceNodePath;
}
var mappers = GetMaps(nodeStructureType);
var mappers = GetMaps(nodeStructureType);
var lastResortRule = GetLastResortRemappingRule();

Log.LogDebug("NodeStructureEnricher.GetNewNodeName::Mappers", mappers);
Expand Down Expand Up @@ -315,15 +313,6 @@ protected void EntryForProcessorType(TfsProcessor processor)
_targetCommonStructureService = processor.Target.GetService<ICommonStructureService4>();
_targetLanguageMaps = processor.Target.Options.LanguageMaps;
_targetProjectName = processor.Target.Options.Project;
try
{
_targetProjectInfo = _targetCommonStructureService.GetProjectFromName(_targetProjectName);
}
catch (ProjectException ex)
{
throw new MigrationToolsException(ex, MigrationToolsException.ExceptionSource.Configuration);
}

}
}
}
Expand Down Expand Up @@ -415,8 +404,6 @@ private static string GetUserFriendlyPath(string systemNodePath)
private void MigrateAllNodeStructures()
{
Log.LogDebug("NodeStructureEnricher.MigrateAllNodeStructures(@{areaMaps}, @{iterationMaps})", Options.Areas, Options.Iterations);


//////////////////////////////////////////////////
ProcessCommonStructure(_sourceLanguageMaps.AreaPath, _targetLanguageMaps.AreaPath, _targetProjectName, TfsNodeStructureType.Area);
//////////////////////////////////////////////////
Expand All @@ -438,9 +425,8 @@ private string GetLocalizedNodeStructureTypeName(TfsNodeStructureType value, Tfs

case TfsNodeStructureType.Iteration:
return languageMap.IterationPath.IsNullOrEmpty() ? "Iteration" : languageMap.IterationPath;

default:
throw new InvalidOperationException("Not a valid NodeStructureType ");
throw new InvalidOperationException("Not a valid NodeStructureType ").AsMigrationToolsException(MigrationToolsException.ExceptionSource.Internal);
}
}

Expand All @@ -464,7 +450,7 @@ private void ProcessCommonStructure(string treeTypeSource, string localizedTreeT
{
Exception ex = new Exception(string.Format("Unable to load Common Structure for Source. This is usually due to different language versions. Validate that '{0}' is the correct name in your version. ", treeTypeSource));
Log.LogError(ex, "Unable to load Common Structure for Source.");
throw ex;
throw ex.AsMigrationToolsException(MigrationToolsException.ExceptionSource.Configuration);
}
XmlElement sourceTree = _sourceCommonStructureService.GetNodesXml(new string[] { sourceNode.Uri }, true);
NodeInfo structureParent;
Expand All @@ -475,9 +461,7 @@ private void ProcessCommonStructure(string treeTypeSource, string localizedTreeT
catch (Exception ex)
{
Exception ex2 = new Exception(string.Format("Unable to load Common Structure for Target.This is usually due to TFS having a different installed langauge version than was expected.. Validate that '{0}' is the correct name in your version. This would be something like 'Fläche' or 'Aire'. If you open the area tree in Visual Studio, or web access, you should see the name your langauage uses for 'Area' or 'Iteration. Do not try to add a specific area or iteration path to this field. Check the defaults on https://nkdagility.com/learn/azure-devops-migration-tools/Reference/Endpoints/TfsTeamProjectEndpoint/ for an example fro English.", localizedTreeTypeName), ex);
Log.LogError(ex2, "Unable to load Common Structure for Target.");
Telemetry.TrackException(ex2, null);
throw ex2;
throw ex2.AsMigrationToolsException(MigrationToolsException.ExceptionSource.Configuration);
}

_pathToKnownNodeMap[structureParent.Path] = structureParent;
Expand Down Expand Up @@ -751,7 +735,7 @@ public string FixAreaPathAndIterationPathForTargetQuery(string sourceWIQLQuery,
structureType = TfsNodeStructureType.Iteration;
break;
default:
throw new InvalidOperationException($"Field type {fieldType} is not supported for query remapping.");
throw new InvalidOperationException($"Field type {fieldType} is not supported for query remapping.").AsMigrationToolsException(MigrationToolsException.ExceptionSource.Internal);
}

var remappedPath = GetNewNodeName(value, structureType);
Expand Down
10 changes: 9 additions & 1 deletion src/MigrationTools/Exceptions/MigrationToolsException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
using System.Collections.Generic;
using System.Text;
using Elmah.Io.Client;
using static MigrationTools.Exceptions.MigrationToolsException;

namespace MigrationTools.Exceptions
{


public static class MigrationToolsExceptionExtensions
{
public static MigrationToolsException AsMigrationToolsException(this Exception ex, ExceptionSource errorSource)
{
return new MigrationToolsException(ex, errorSource);
}
}

public class MigrationToolsException : Exception
{
Expand Down
Loading