Skip to content

Commit b8949b2

Browse files
committed
Reuse the exception message
1 parent fbc84e7 commit b8949b2

File tree

7 files changed

+8
-12
lines changed

7 files changed

+8
-12
lines changed

src/cluster/DotNext.AspNetCore.Cluster/ExceptionMessages.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ internal static string MissingHeader(string headerName)
1616

1717
internal static string IncorrectResponse => (string)Resources.Get();
1818

19-
internal static string UnavailableMember => (string)Resources.Get();
20-
21-
internal static string LeaderIsUnavailable => (string)Resources.Get();
22-
2319
internal static string InvalidRpcTimeout => (string)Resources.Get();
2420

2521
internal static string UnsupportedRedirection => (string)Resources.Get();

src/cluster/DotNext.AspNetCore.Cluster/ExceptionMessages.restext

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
MissingHeader=Raft protocol header {0} is missing
22
IncorrectResponse=Incorrect response according to Raft protocol
3-
UnavailableMember=Member is not reachable through the network
4-
LeaderIsUnavailable=Leader node is not yet elected
53
InvalidRpcTimeout=Raft RPC timeout cannot be larger than HTTP request timeout
64
UnsupportedRedirection=Redirection is not supported because the underlying network transport for Raft cannot provide correct resolution of the leader address compatible with HTTP protocol
75
ReadLogEntryTwice=Attempt to read the log entry twice while it's not reusable

src/cluster/DotNext.AspNetCore.Cluster/Net/Cluster/Consensus/Raft/Http/RaftClusterMember.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ MemberUnavailableException MemberUnavailable(Exception e)
137137
{
138138
context.Logger.MemberUnavailable(EndPoint, e);
139139
Status = ClusterMemberStatus.Unavailable;
140-
return new MemberUnavailableException(this, ExceptionMessages.UnavailableMember, e);
140+
return new MemberUnavailableException(this, innerException: e);
141141
}
142142
}
143143

src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/LeaderState.Replication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ internal ValueTask ForceReplicationAsync(CancellationToken token)
231231
}
232232
catch (ObjectDisposedException e)
233233
{
234-
replicationTask = ValueTask.FromException(new InvalidOperationException(ExceptionMessages.LocalNodeNotLeader, e));
234+
replicationTask = ValueTask.FromException(new NotLeaderException(e));
235235
}
236236

237237
return replicationTask;
@@ -246,7 +246,7 @@ internal void ForceReplication()
246246
}
247247
catch (ObjectDisposedException e)
248248
{
249-
throw new InvalidOperationException(ExceptionMessages.LocalNodeNotLeader, e);
249+
throw new NotLeaderException(e);
250250
}
251251
}
252252

src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/LeaderState.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using System.Diagnostics.Metrics;
33
using System.Runtime.CompilerServices;
4+
using DotNext.Net.Cluster.Replication;
45
using Microsoft.Extensions.Logging;
56

67
namespace DotNext.Net.Cluster.Consensus.Raft;
@@ -282,7 +283,7 @@ protected override void Dispose(bool disposing)
282283
DestroyLease();
283284

284285
// cancel replication queue
285-
replicationQueue.Dispose(new InvalidOperationException(ExceptionMessages.LocalNodeNotLeader));
286+
replicationQueue.Dispose(new NotLeaderException());
286287
replicationEvent.Dispose();
287288

288289
context.Dispose();

src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/TransportServices/ConnectionOriented/Client.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private async Task<TResponse> RequestAsync<TResponse, TExchange>(TExchange excha
105105

106106
// detect broken socket
107107
ClearContext();
108-
throw new MemberUnavailableException(this, ExceptionMessages.UnavailableMember, e);
108+
throw new MemberUnavailableException(this, innerException: e);
109109
}
110110
finally
111111
{

src/cluster/DotNext.Net.Cluster/Net/Cluster/MemberUnavailableException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
/// <param name="member">The unavailable member.</param>
77
/// <param name="message">Human-readable text describing the issue.</param>
88
/// <param name="innerException">The underlying network-related exception.</param>
9-
public class MemberUnavailableException(IClusterMember member, string message, Exception? innerException = null) : IOException(message, innerException)
9+
public class MemberUnavailableException(IClusterMember member, string? message = null, Exception? innerException = null)
10+
: IOException(message ?? ExceptionMessages.UnavailableMember, innerException)
1011
{
1112
/// <summary>
1213
/// Gets unavailable member.

0 commit comments

Comments
 (0)