Skip to content

Commit 2159745

Browse files
committed
replace Parse with TryParse
1 parent 69e2000 commit 2159745

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public static bool TryParse(string version, string tagPrefixRegex, out SemanticV
191191
Major = major,
192192
Minor = minor,
193193
Patch = patch,
194-
PreReleaseTag = SemanticVersionPreReleaseTag.Parse(parsed.Groups["Tag"].Value),
194+
PreReleaseTag = SemanticVersionPreReleaseTag.TryParse(parsed.Groups["Tag"].Value),
195195
BuildMetaData = semanticVersionBuildMetaData
196196
};
197197

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public static SemanticVersionPreReleaseTag TryParse(string preReleaseTag)
103103
}
104104

105105
var value = match.Groups["name"].Value;
106-
var number = match.Groups["number"].Success ? int.Parse(match.Groups["number"].Value) : (int?)null;
106+
var number = (match.Groups["number"].Success && int.TryParse(match.Groups["number"].Value, out int parsedNumber)) ? (int?)parsedNumber : null;
107+
107108
if (value.EndsWith("-"))
108109
return new SemanticVersionPreReleaseTag(preReleaseTag, null);
109110

0 commit comments

Comments
 (0)