Skip to content

Commit 6824b67

Browse files
committed
Introduce AuthenticationException.
1 parent 07b6b1a commit 6824b67

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using LibGit2Sharp.Core;
4+
5+
namespace LibGit2Sharp
6+
{
7+
/// <summary>
8+
/// The exception that is thrown when an operation which requires an
9+
/// authentation fails.
10+
/// </summary>
11+
[Serializable]
12+
public class AuthenticationException : LibGit2SharpException
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class.
16+
/// </summary>
17+
public AuthenticationException()
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a specified error message.
23+
/// </summary>
24+
/// <param name="message">A message that describes the error.</param>
25+
public AuthenticationException(string message)
26+
: base(message)
27+
{
28+
}
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
32+
/// </summary>
33+
/// <param name="message">The error message that explains the reason for the exception.</param>
34+
/// <param name="innerException">The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.</param>
35+
public AuthenticationException(string message, Exception innerException)
36+
: base(message, innerException)
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="LibGit2Sharp.AuthenticationException"/> class with a serialized data.
42+
/// </summary>
43+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
44+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
45+
protected AuthenticationException(SerializationInfo info, StreamingContext context)
46+
: base(info, context)
47+
{
48+
}
49+
50+
internal AuthenticationException(string message, GitErrorCode code, GitErrorCategory category)
51+
: base(message, code, category)
52+
{
53+
}
54+
}
55+
}

LibGit2Sharp/Core/Ensure.cs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCode, GitE
100100
{ GitErrorCode.NonFastForward, (m, r, c) => new NonFastForwardException(m, r, c) },
101101
{ GitErrorCode.MergeConflict, (m, r, c) => new MergeConflictException(m, r, c) },
102102
{ GitErrorCode.LockedFile, (m, r, c) => new LockedFileException(m, r, c) },
103+
{ GitErrorCode.Auth, (m, r, c) => new AuthenticationException(m, r, c) },
103104
};
104105

105106
private static void HandleError(int result)

LibGit2Sharp/Core/GitErrorCode.cs

+10
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ internal enum GitErrorCode
7070
/// </summary>
7171
Modified = -15,
7272

73+
/// <summary>
74+
/// Authentication error.
75+
/// </summary>
76+
Auth = -16,
77+
78+
/// <summary>
79+
/// Server certificate is invalid.
80+
/// </summary>
81+
Certificate = -17,
82+
7383
/// <summary>
7484
/// Skip and passthrough the given ODB backend.
7585
/// </summary>

LibGit2Sharp/LibGit2Sharp.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@
340340
<Compile Include="SshUserCredentials.cs" />
341341
<Compile Include="SshUserKeyCredentials.cs" />
342342
<Compile Include="SshAgentCredentials.cs" />
343+
<Compile Include="AuthenticationException.cs" />
343344
</ItemGroup>
344345
<ItemGroup>
345346
<CodeAnalysisDictionary Include="CustomDictionary.xml" />

0 commit comments

Comments
 (0)