Skip to content

Commit 13cf1df

Browse files
committed
Throw more helpful error message when version.json fails to parse
Fixes #251
1 parent 3443778 commit 13cf1df

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/NerdBank.GitVersioning/SemanticVersionJsonConverter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
2424
{
2525
return value;
2626
}
27+
else
28+
{
29+
throw new FormatException($"The value \"{reader.Value}\" is not a valid semantic version.");
30+
}
2731
}
2832

2933
throw new NotSupportedException();

src/NerdBank.GitVersioning/VersionFile.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,19 @@ public static VersionOptions GetVersion(LibGit2Sharp.Commit commit, string repoR
6969
versionJsonContent = sr.ReadToEnd();
7070
}
7171

72-
VersionOptions result = TryReadVersionJsonContent(versionJsonContent);
72+
VersionOptions result;
73+
try
74+
{
75+
result = TryReadVersionJsonContent(versionJsonContent);
76+
}
77+
catch (FormatException ex)
78+
{
79+
throw new FormatException(
80+
$"Failure while reading {JsonFileName} from commit {commit.Sha}. " +
81+
"Fix this commit with rebase if this is an error, or review this doc on how to migrate to Nerdbank.GitVersioning: " +
82+
"https://github.com/AArnott/Nerdbank.GitVersioning/blob/master/doc/migrating.md", ex);
83+
}
84+
7385
if (result?.Inherit ?? false)
7486
{
7587
if (parentDirectory != null)

0 commit comments

Comments
 (0)