Skip to content

Commit e66c642

Browse files
Alexander OvchinnikovMarcellvanRooyen
Alexander Ovchinnikov
andcommitted
Set ErrorCategory when git_error_last returns a valid error
Restore the corresponding constructor in LibGit2SharpException Co-authored-by: Marcell van Rooyen <[email protected]>
1 parent 26dd4b6 commit e66c642

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

LibGit2Sharp/Core/Ensure.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,13 @@ private static unsafe void HandleError(int result)
143143
else
144144
{
145145
errorMessage = LaxUtf8Marshaler.FromNative(error->Message);
146+
errorCategory = error->Category;
146147
}
147148

148149
Func<string, GitErrorCategory, LibGit2SharpException> exceptionBuilder;
149150
if (!GitErrorsToLibGit2SharpExceptions.TryGetValue((GitErrorCode)result, out exceptionBuilder))
150151
{
151-
exceptionBuilder = (m, c) => new LibGit2SharpException(m, c);
152+
exceptionBuilder = (m, c) => new LibGit2SharpException(m, (GitErrorCode)result, c);
152153
}
153154

154155
throw exceptionBuilder(errorMessage, errorCategory);

LibGit2Sharp/LibGit2SharpException.cs

+6
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@ public LibGit2SharpException(string format, params object[] args)
5252
protected LibGit2SharpException(SerializationInfo info, StreamingContext context)
5353
: base(info, context)
5454
{ }
55+
56+
internal LibGit2SharpException(string message, GitErrorCode code, GitErrorCategory category) : this(message)
57+
{
58+
Data.Add("libgit2.code", (int)code);
59+
Data.Add("libgit2.category", (int)category);
60+
}
5561
}
5662
}

0 commit comments

Comments
 (0)