Skip to content

Commit a48853a

Browse files
authored
Update to field to fields (#2999)
This pull request introduces improvements to error handling and logging for image download and field mapping operations in the migration tools. The most notable changes are enhanced diagnostics for failed image downloads and field value mappings, and a modification to HTTP client configuration to allow redirects. **Error handling and diagnostics improvements:** * Added detailed logging for failed image downloads in `TfsEmbededImagesTool.cs`, including HTTP status codes and reason phrases for non-404 errors. * Enhanced debugging information in `EmbededImagesRepairEnricherBase.cs` by logging failed HTTP responses, including status codes, reason phrases, and location headers. **Field mapping logic:** * Updated `FieldToFieldMap.cs` to log when a field mapping is skipped due to an empty value, providing clearer diagnostics for mapping operations. **HTTP client configuration:** * Changed the HTTP client handler in `EmbededImagesRepairEnricherBase.cs` to allow automatic redirects, improving compatibility with redirected image URLs.
2 parents 5184e80 + 2d2b6a7 commit a48853a

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps/FieldToFieldMap.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,17 @@ internal override void InternalExecute(WorkItem source, WorkItem target)
6666
value = Config.defaultValue;
6767
}
6868

69-
target.Fields[Config.targetField].Value = value;
70-
Log.LogDebug("FieldToFieldMap: [UPDATE] Successfully mapped field {SourceField} to {TargetField} with value '{Value}' using mode {FieldMapMode} | Source WorkItem: {SourceId} -> Target WorkItem: {TargetId}",
71-
Config.sourceField, Config.targetField, value, Config.fieldMapMode, source.Id, target.Id);
69+
if (!string.IsNullOrEmpty(value))
70+
{
71+
target.Fields[Config.targetField].Value = value;
72+
Log.LogDebug("FieldToFieldMap: [UPDATE] Successfully mapped field {SourceField} to {TargetField} with value '{Value}' using mode {FieldMapMode} | Source WorkItem: {SourceId} -> Target WorkItem: {TargetId}",
73+
Config.sourceField, Config.targetField, value, Config.fieldMapMode, source.Id, target.Id);
74+
}
75+
else
76+
{
77+
Log.LogDebug("FieldToFieldMap: [SKIPPED] Proposed value is empty {SourceField} to {TargetField} with value '{Value}' using mode {FieldMapMode} | Source WorkItem: {SourceId} -> Target WorkItem: {TargetId}",
78+
Config.sourceField, Config.targetField, value, Config.fieldMapMode, source.Id, target.Id);
79+
}
7280
}
7381

7482
private bool IsValid(WorkItem source, WorkItem target)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ private string UploadedAndRetrieveAttachmentLinkUrl(string matchedSourceUri, str
150150
}
151151
else
152152
{
153+
// Provide more detailed error information for non-404 failures
154+
Log.LogWarning("EmbededImagesRepairEnricher: Failed to download image {MatchValue} from WorkItem {WorkItemId}, Field {FieldName}. Status: {StatusCode} ({ReasonPhrase})",
155+
matchedSourceUri, targetWorkItem.Id, sourceFieldName, (int)result.StatusCode, result.ReasonPhrase);
156+
153157
result.EnsureSuccessStatusCode();
154158
}
155159
}

src/MigrationTools/Tools/Infrastructure/EmbededImagesRepairEnricherBase.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace MigrationTools.Tools.Infrastructure
1818

1919
protected EmbededImagesRepairToolBase(IOptions<ToolOptions> options, IServiceProvider services, ILogger<ITool> logger, ITelemetryLogger telemetry) : base(options, services, logger, telemetry)
2020
{
21-
_httpClientHandler = new HttpClientHandler { AllowAutoRedirect = false, UseDefaultCredentials = true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate };
21+
_httpClientHandler = new HttpClientHandler { AllowAutoRedirect = true, UseDefaultCredentials = true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate };
2222
}
2323

2424
/**
@@ -41,6 +41,13 @@ protected static HttpResponseMessage DownloadFile(HttpClient httpClient, string
4141
}
4242
}
4343
}
44+
else
45+
{
46+
// Log details about non-success responses for debugging
47+
var logger = Microsoft.Extensions.Logging.LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger("EmbededImagesRepairEnricher");
48+
logger.LogDebug("DownloadFile failed for URL {Url}. Status: {StatusCode} ({ReasonPhrase}). Location header: {LocationHeader}",
49+
url, (int)response.StatusCode, response.ReasonPhrase, response.Headers.Location?.ToString() ?? "None");
50+
}
4451

4552
return response;
4653
}
@@ -126,4 +133,4 @@ protected enum ImageFormat
126133
jpeg
127134
}
128135
}
129-
}
136+
}

0 commit comments

Comments
 (0)