Skip to content

The local cluster member is not a leader - Change exception type from InvalidOperationException to a more specific NotALeaderException #276

@pwhsoft

Description

@pwhsoft

Currently, when attempting to perform a Raft operation on a non-leader node, the following exception is thrown:

System.InvalidOperationException: The local cluster member is not a leader
 ---> System.OperationCanceledException: The operation was canceled.

Problem:
InvalidOperationException is too generic for this scenario and makes it difficult to distinguish between general invalid operations and leadership-related errors.

Suggestion:
Introduce a more specific exception type (e.g., NotALeaderException, LeaderUnavailableException, or similar) to clearly signal that the operation failed because the current node is not the Raft cluster leader.

Rationale:

Improves error handling for client applications.

Makes it easier to implement leader redirection or retry logic.

Better reflects the semantics of Raft operations.

Stack trace (for reference):

System.InvalidOperationException: The local cluster member is not a leader
 ---> System.OperationCanceledException: The operation was canceled.
   at DotNext.Result`1.get_Value() in /_/src/DotNext/Result.cs:line 177
   ...
   at DotNext.Net.Cluster.Consensus.Raft.RaftCluster`1.ReplicateAsync[TEntry](TEntry entry, CancellationToken token)

Metadata

Metadata

Assignees

Labels

Lib:ClusterDotNext.Net.Cluster library

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions