8000 Set ErrorCategory when git_error_last returns a valid error · mendix/libgit2sharp@a080786 · GitHub
[go: up one dir, main page]

Skip to content

Commit a080786

Browse files
MarcellvanRooyenAlexander Ovchinnikov
authored andcommitted
Set ErrorCategory when git_error_last returns a valid error
Make GitErrorCategory and GitErrorCode public instead of internal
1 parent 05b0ef7 commit a080786

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

LibGit2Sharp/Core/Ensure.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,13 @@ private static unsafe void HandleError(int result)
154154
else
155155
{
156156
errorMessage = LaxUtf8Marshaler.FromNative(error->Message);
157+
errorCategory = error->Category;
157158
}
158159

159160
Func<string, GitErrorCategory, LibGit2SharpException> exceptionBuilder;
160161
if (!GitErrorsToLibGit2SharpExceptions.TryGetValue((GitErrorCode)result, out exceptionBuilder))
161162
{
162-
exceptionBuilder = (m, c) => new LibGit2SharpException(m, c);
163+
exceptionBuilder = (m, c) => new LibGit2SharpException(m, (GitErrorCode)result, c);
163164
}
164165

165166
throw exceptionBuilder(errorMessage, errorCategory);

LibGit2Sharp/Core/GitErrorCategory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace LibGit2Sharp.Core
22
{
3-
internal enum GitErrorCategory
3+
public enum GitErrorCategory
44
{
55
Unknown = -1,
66
None,
@@ -36,6 +36,8 @@ internal enum GitErrorCategory
3636
Filesystem,
3737
Patch,
3838
Worktree,
39-
Sha1
39+
Sha1,
40+
Http,
41+
Internal
4042
}
4143
}

LibGit2Sharp/Core/GitErrorCode.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
namespace LibGit2Sharp.Core
22
{
3-
internal enum GitErrorCode
3+
/// <summary>
4+
/// Git Error Code contains a list of possible error codes returned by LibGit2
5+
/// </summary>
6+
public enum GitErrorCode
47
{
8+
/// <summary>
9+
/// No Error result OK
10+
/// </summary>
511
Ok = 0,
12+
13+
/// <summary>
14+
/// General Error
15+
/// </summary>
616
Error = -1,
717

818
/// <summary>

LibGit2Sharp/LibGit2SharpException.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,24 @@ 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+
61+
Code = code;
62+
Category = category;
63+
}
64+
65+
/// <summary>
66+
/// The underlying GitErrorCode returned by LibGit2
67+
/// </summary>
68+
public GitErrorCode Code { get; private set; }
69+
70+
/// <summary>
71+
/// The underlying Error Category returned by LibGit2
72+
/// </summary>
73+
public GitErrorCategory Category { get; private set; }
5574
}
5675
}

0 commit comments

Comments
 (0)
0