Skip to content

Commit 35882de

Browse files
Copilotalerickson
andcommitted
Add exception handling for LoadXDocument validation in Reset method
Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com>
1 parent 357437e commit 35882de

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/code/RepositorySettings.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,27 @@ public static PSRepositoryInfo Reset(PSCmdlet cmdletPassedIn, out string errorMs
871871
newRepoXML.Save(tempFilePath);
872872

873873
// Validate that the temporary file can be loaded
874-
LoadXDocument(tempFilePath);
874+
try
875+
{
876+
LoadXDocument(tempFilePath);
877+
}
878+
catch (Exception loadEx)
879+
{
880+
// Clean up temp file on validation failure
881+
if (File.Exists(tempFilePath))
882+
{
883+
try
884+
{
885+
File.Delete(tempFilePath);
886+
}
887+
catch
888+
{
889+
// Ignore cleanup errors for temp file
890+
}
891+
}
892+
errorMsg = string.Format(CultureInfo.InvariantCulture, "Failed to validate newly created repository store file with error: {0}.", loadEx.Message);
893+
return null;
894+
}
875895

876896
// Back up the existing file if it exists
877897
if (File.Exists(FullRepositoryPath))

0 commit comments

Comments
 (0)