Skip to content

Commit

Permalink
Issue with TfsEmbededImagesTool and Rules
Browse files Browse the repository at this point in the history
🐛 (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
MrHinsh authored Jan 27, 2025
2 parents ebfa90b + d552cc9 commit 9ffd253
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq.Expressions;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
@@ -158,6 +159,9 @@ private string UploadedAndRetrieveAttachmentLinkUrl(string matchedSourceUri, str

return attachRef.Url;
}
catch (Exception ex) {
throw ex;
}
finally
{
if (File.Exists(fullImageFilePath))
@@ -239,9 +243,33 @@ private WorkItem GetDummyWorkItem(WorkItemType type = null)

_targetDummyWorkItem = type.NewWorkItem();
_targetDummyWorkItem.Title = TargetDummyWorkItemTitle;

var fails = _targetDummyWorkItem.Validate();
if (fails.Count > 0)
{
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.");
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
foreach (Field f in fails)
{
Log.LogDebug("Invalid Field Object:\r\n{Field}", f.ToJson());
}
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
}
Log.LogTrace("TfsEmbededImagesTool::GetDummyWorkItem::Save()");


_targetDummyWorkItem.Save();
Log.LogDebug("EmbededImagesRepairEnricher: Dummy workitem {id} created on the target collection.", _targetDummyWorkItem.Id);
//_targetProject.Store.DestroyWorkItems(new List<int> { _targetDummyWorkItem.Id });

if (_targetDummyWorkItem.Id == 0)
{
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.");
} else
{
Log.LogDebug("TfsEmbededImagesTool: Dummy workitem {id} created on the target collection.", _targetDummyWorkItem.Id);
//_targetProject.Store.DestroyWorkItems(new List<int> { _targetDummyWorkItem.Id });
}
}
_DummyWorkItemCount++;
return _targetDummyWorkItem;

0 comments on commit 9ffd253

Please sign in to comment.