Skip to content

Commit 9ffd253

Browse files
authored
Issue with TfsEmbededImagesTool and Rules
🐛 (TfsEmbededImagesTool.cs): improve error handling and logging for dummy work item creation Add exception handling to provide more informative error messages when exceptions occur. Enhance logging to warn about invalid fields in the dummy work item and ensure that the work item is ready to save. This change helps in diagnosing issues related to work item creation by providing detailed logs and throwing exceptions when the dummy work item cannot be created due to save failures. Fix for #2589 (or at least visibility) created by @anderssonpof
2 parents ebfa90b + d552cc9 commit 9ffd253

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq.Expressions;
45
using System.Net;
56
using System.Net.Http;
67
using System.Net.Http.Headers;
@@ -158,6 +159,9 @@ private string UploadedAndRetrieveAttachmentLinkUrl(string matchedSourceUri, str
158159

159160
return attachRef.Url;
160161
}
162+
catch (Exception ex) {
163+
throw ex;
164+
}
161165
finally
162166
{
163167
if (File.Exists(fullImageFilePath))
@@ -239,9 +243,33 @@ private WorkItem GetDummyWorkItem(WorkItemType type = null)
239243

240244
_targetDummyWorkItem = type.NewWorkItem();
241245
_targetDummyWorkItem.Title = TargetDummyWorkItemTitle;
246+
247+
var fails = _targetDummyWorkItem.Validate();
248+
if (fails.Count > 0)
249+
{
250+
Log.LogWarning("Dummy Work Item is not ready to save as it has some invalid fields. This may not result in an error. Enable LogLevel as 'Debug' in the config to see more.");
251+
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
252+
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
253+
foreach (Field f in fails)
254+
{
255+
Log.LogDebug("Invalid Field Object:\r\n{Field}", f.ToJson());
256+
}
257+
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
258+
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
259+
}
260+
Log.LogTrace("TfsEmbededImagesTool::GetDummyWorkItem::Save()");
261+
262+
242263
_targetDummyWorkItem.Save();
243-
Log.LogDebug("EmbededImagesRepairEnricher: Dummy workitem {id} created on the target collection.", _targetDummyWorkItem.Id);
244-
//_targetProject.Store.DestroyWorkItems(new List<int> { _targetDummyWorkItem.Id });
264+
265+
if (_targetDummyWorkItem.Id == 0)
266+
{
267+
throw new Exception("The Dummy work Item cant be created due to a save failure. This is likley due to required fields on the Task or First work items type.");
268+
} else
269+
{
270+
Log.LogDebug("TfsEmbededImagesTool: Dummy workitem {id} created on the target collection.", _targetDummyWorkItem.Id);
271+
//_targetProject.Store.DestroyWorkItems(new List<int> { _targetDummyWorkItem.Id });
272+
}
245273
}
246274
_DummyWorkItemCount++;
247275
return _targetDummyWorkItem;

0 commit comments

Comments
 (0)