Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error { NotLeader { leader: Option<NodeId>, }, Storage { context: &'static str, detail: String, }, Encoding { context: &'static str, detail: String, }, ConfigInProgress, }
Expand description

Everything that can go wrong while driving a RaftNode.

The type is #[non_exhaustive]: later phases (persistence, snapshots) add variants without a major bump, so a match over it must include a wildcard arm.

§Examples

use raft_io::Error;

// A proposal sent to a follower is rejected with a hint to the leader.
let err = Error::NotLeader { leader: Some(3) };
assert_eq!(err.to_string(), "not the leader; current leader is node 3");

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

NotLeader

A client proposal was made to a node that is not the leader.

Only the leader may accept proposals. leader carries the node’s best knowledge of who the current leader is, so the caller can redirect the request; it is None when no leader is known (for example during an election). This is a normal, recoverable condition — retry against the indicated leader.

Fields

§leader: Option<NodeId>

The node believed to be the current leader, if known.

§

Storage

A RaftLog backend operation failed.

The in-memory log never produces this, but a durable backend (the wal-db-backed log arriving in v0.4) can fail to read, append, or flush. context names the operation that was attempted (for example "append entries" or "sync log") so the message is actionable, and detail carries the backend’s own description. The caller should treat a storage failure on the durability path as fatal to the node: a node that cannot persist its state must not continue participating.

Fields

§context: &'static str

What the log was trying to do when the failure occurred.

§detail: String

The underlying backend error, rendered as text.

§

Encoding

A message failed to encode to or decode from its wire form.

Produced by the framing module (the framing feature) when pack-io cannot serialize a message or a received byte string does not decode into a valid one. context names the operation and detail carries the codec’s description. A decode failure is not fatal — the transport should drop the malformed message and carry on, exactly as Raft tolerates a lost one.

Fields

§context: &'static str

What the framing layer was doing when it failed.

§detail: String

The underlying codec error, rendered as text.

§

ConfigInProgress

A membership change was requested while a previous one is still in flight.

Raft changes the configuration one server at a time, and the leader must not begin a new change until the previous configuration entry has committed. Retry once the in-flight change completes. This is a routine, retryable condition.

Implementations§

Source§

impl Error

Source

pub fn storage(context: &'static str, source: impl Display) -> Self

Builds a Storage error from any displayable backend error.

Backends implementing RaftLog use this to map their own error type into the crate’s error without naming its fields.

§Examples
use raft_io::Error;

let io = std::io::Error::new(std::io::ErrorKind::Other, "disk full");
let err = Error::storage("append entries", io);
assert!(err.to_string().contains("disk full"));
Source

pub fn encoding(context: &'static str, source: impl Display) -> Self

Builds an Encoding error from any displayable codec error. Used by the framing layer.

§Examples
use raft_io::Error;

let err = Error::encoding("decode message", "unexpected end of input");
assert!(err.to_string().contains("unexpected end of input"));

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl ForgeError for Error

Source§

fn is_retryable(&self) -> bool

A NotLeader rejection is retryable against the indicated leader and a ConfigInProgress rejection is retryable once the change completes; a storage failure on the durability path is not.

Source§

fn is_fatal(&self) -> bool

A storage failure means the node can no longer guarantee durability and should stop; a NotLeader rejection is a routine redirect.

Source§

fn kind(&self) -> &'static str

Returns the kind of error, typically matching the enum variant
Source§

fn caption(&self) -> &'static str

Returns a human-readable caption for the error
Source§

fn status_code(&self) -> u16

Returns an appropriate HTTP status code for the error
Source§

fn exit_code(&self) -> i32

Returns an appropriate process exit code for the error
Source§

fn user_message(&self) -> String

Returns a user-facing message that can be shown to end users
Source§

fn dev_message(&self) -> String

Returns a detailed technical message for developers/logs
Source§

fn backtrace(&self) -> Option<&Backtrace>

Returns a backtrace if available
Source§

fn register(&self)

Registers the error with the central error registry

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ForgeErrorRecovery for T
where T: ForgeError,

Source§

fn create_retry_policy(&self, max_retries: usize) -> RetryPolicy

Create a retry policy optimized for this error type
Source§

fn retry<F, T, E>(&self, max_retries: usize, operation: F) -> Result<T, E>
where F: FnMut() -> Result<T, E>, E: ForgeError,

Execute a fallible operation with retries if this error type is retryable
Source§

fn create_circuit_breaker(&self, name: impl Into<String>) -> CircuitBreaker

Create a circuit breaker for operations that might result in this error type
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<E> WithErrorCode<E> for E

Source§

fn with_code(self, code: impl Into<String>) -> CodedError<E>

Attach an error code to an error