Error

Enum Error 

Source
pub enum Error {
    Io(Error),
    Config(String),
    Control(Error),
    State(String),
    Consensus(String),
    NoNodesRemain,
    Validation(String),
    DescriptorUnavailable(String),
}
Expand description

Errors that can occur during vanguards-rs operations.

This enum represents all possible error conditions in the library. Each variant provides specific information about the failure and guidance on recovery.

§Error Handling Patterns

§Match on Specific Errors

use vanguards_rs::Error;

fn handle_error(err: Error) {
    match err {
        Error::Io(io_err) => {
            eprintln!("I/O error: {}", io_err);
            // Check file permissions, disk space, network
        }
        Error::Config(msg) => {
            eprintln!("Configuration error: {}", msg);
            // Fix configuration and restart
        }
        Error::Control(ctrl_err) => {
            eprintln!("Tor control error: {}", ctrl_err);
            // Reconnect to Tor
        }
        Error::State(msg) => {
            eprintln!("State file error: {}", msg);
            // Delete state file and restart
        }
        Error::Consensus(msg) => {
            eprintln!("Consensus error: {}", msg);
            // Wait for Tor to get new consensus
        }
        Error::NoNodesRemain => {
            eprintln!("No nodes remain after filtering");
            // Adjust ExcludeNodes configuration
        }
        Error::Validation(msg) => {
            eprintln!("Validation error: {}", msg);
            // Fix invalid input
        }
        Error::DescriptorUnavailable(msg) => {
            eprintln!("Descriptor unavailable: {}", msg);
            // Wait for Tor to finish bootstrapping
        }
    }
}

§Check if Retryable

use vanguards_rs::Error;

fn is_retryable(err: &Error) -> bool {
    matches!(err,
        Error::Io(_) |
        Error::Control(_) |
        Error::Consensus(_) |
        Error::DescriptorUnavailable(_)
    )
}

§See Also

  • Result - Type alias using this error type
  • [stem_rs::Error] - Underlying control protocol errors

Variants§

§

Io(Error)

I/O error during file or network operations.

This error wraps standard I/O errors that occur during file operations (reading/writing state files, config files) or network operations.

§Recovery

  • Check file permissions and paths
  • Retry with exponential backoff for transient issues
  • Verify disk space for write operations
§

Config(String)

Configuration error.

This error indicates invalid configuration values or parsing failures. The message describes what was wrong with the configuration.

§Recovery

Fix the configuration file or command-line arguments. This error is not recoverable without user intervention.

§

Control(Error)

Tor control protocol error.

This error wraps errors from stem-rs when communicating with Tor’s control port.

§Recovery

  • Check if Tor is running
  • Verify control port configuration
  • Retry connection with backoff
§

State(String)

State file error.

This error indicates problems with the vanguard state file, such as corruption, invalid format, or incompatible version.

§Recovery

  • Delete the corrupted state file and let vanguards create a fresh one
  • Check file permissions
  • Verify the file wasn’t modified externally
§

Consensus(String)

Consensus parsing error.

This error occurs when parsing the network consensus fails.

§Recovery

  • Wait for a new consensus
  • Verify Tor has finished bootstrapping
  • Check DataDirectory configuration
§

NoNodesRemain

No nodes remain after applying restrictions.

This error occurs when all relays are filtered out by the configured restrictions (ExcludeNodes, flag requirements, etc.).

§Recovery

  • Review ExcludeNodes configuration
  • Reduce restrictions
  • Wait for more relays to appear in consensus
§

Validation(String)

Input validation error.

This error indicates that input data failed validation checks.

§Recovery

Fix the invalid input. This error is not recoverable without correcting the input data.

§

DescriptorUnavailable(String)

Descriptor unavailable.

This error occurs when Tor doesn’t have the required descriptors cached yet, typically during bootstrap.

§Recovery

  • Wait for Tor to finish bootstrapping
  • Retry after a short delay

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, __formatter: &mut Formatter<'_>) -> Result

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

impl Error for Error

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 From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more