Skip to content

Commit 329e663

Browse files
committed
Handle failure to parse integers
1 parent 8bb99a1 commit 329e663

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,29 @@ public static bool TryParse(string version, string tagPrefixRegex, out SemanticV
170170
semanticVersionBuildMetaData.CommitsSinceTag = int.Parse(fourthPart.Value);
171171
}
172172

173-
semanticVersion = new SemanticVersion
173+
try
174174
{
175-
Major = int.Parse(parsed.Groups["Major"].Value),
176-
Minor = parsed.Groups["Minor"].Success ? int.Parse(parsed.Groups["Minor"].Value) : 0,
177-
Patch = parsed.Groups["Patch"].Success ? int.Parse(parsed.Groups["Patch"].Value) : 0,
178-
PreReleaseTag = SemanticVersionPreReleaseTag.Parse(parsed.Groups["Tag"].Value),
179-
BuildMetaData = semanticVersionBuildMetaData
180-
};
175+
semanticVersion = new SemanticVersion
176+
{
177+
Major = int.Parse(parsed.Groups["Major"].Value),
178+
Minor = parsed.Groups["Minor"].Success ? int.Parse(parsed.Groups["Minor"].Value) : 0,
179+
Patch = parsed.Groups["Patch"].Success ? int.Parse(parsed.Groups["Patch"].Value) : 0,
180+
PreReleaseTag = SemanticVersionPreReleaseTag.Parse(parsed.Groups["Tag"].Value),
181+
BuildMetaData = semanticVersionBuildMetaData
182+
};
183+
} catch(Exception exception)
184+
{
185+
if (exception is FormatException || exception is OverflowException)
186+
{
187+
Console.Error.WriteLine("Failed to Parse Tag:");
188+
Console.Error.WriteLine(exception.Message);
189+
190+
semanticVersion = null;
191+
return false;
192+
}
193+
194+
throw exception;
195+
}
181196

182197
return true;
183198
}

0 commit comments

Comments
 (0)