Skip to content

Commit b1292d0

Browse files
committed
validation fixup per gemini code assist review
1 parent 6c9306d commit b1292d0

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

StabilityMatrix.Core/Python/PipShowResult.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,20 @@ public static PipShowResult Parse(string output)
6464
linesDict.TryAdd(key, value);
6565
}
6666

67+
if (!linesDict.TryGetValue("Name", out var name))
68+
{
69+
throw new FormatException("The 'Name' key was not found in the pip show output.");
70+
}
71+
72+
if (!linesDict.TryGetValue("Version", out var version))
73+
{
74+
throw new FormatException("The 'Version' key was not found in the pip show output.");
75+
}
76+
6777
return new PipShowResult
6878
{
69-
Name = linesDict["Name"],
70-
Version = linesDict["Version"],
79+
Name = name,
80+
Version = version,
7181
Summary = linesDict.GetValueOrDefault("Summary"),
7282
HomePage = linesDict.GetValueOrDefault("Home-page"),
7383
Author = linesDict.GetValueOrDefault("Author"),

StabilityMatrix.Tests/Core/PipShowResultsTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,11 @@ public void TestDuplicatePackageNameInOutput()
174174
Assert.AreEqual("package-a", result.Name);
175175
Assert.AreEqual("1.0.0", result.Version);
176176
}
177+
178+
[TestMethod]
179+
public void TestEmptyInputThrowsFormatException()
180+
{
181+
var input = "";
182+
Assert.ThrowsException<FormatException>(() => PipShowResult.Parse(input));
183+
}
177184
}

0 commit comments

Comments
 (0)