Error

Enum Error 

Source
pub enum Error {
Show 15 variants Socket(Error), Protocol(String), Authentication(AuthError), OperationFailed { code: String, message: String, }, UnsatisfiableRequest(String), InvalidRequest(String), InvalidArguments(String), Parse { location: String, reason: String, }, Download { url: String, reason: String, }, DownloadTimeout { url: String, }, Timeout, SocketClosed, DescriptorUnavailable(String), CircuitExtensionFailed(String), AddrParse(AddrParseError),
}
Expand description

Errors that can occur during stem-rs operations.

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

§Error Categories

  • I/O Errors: Socket - Connection and communication failures
  • Protocol Errors: Protocol - Malformed control protocol data
  • Auth Errors: Authentication - Authentication failures
  • Operation Errors: OperationFailed - Tor rejected the request
  • Parse Errors: Parse - Descriptor parsing failures

§Recovery Guide

ErrorRecoverableRetry Meaningful
SocketSometimesYes, with backoff
ProtocolNoNo
AuthenticationSometimesYes, with different credentials
OperationFailedDepends on codeCheck error code
ParseNoNo
TimeoutYesYes, with longer timeout
SocketClosedYesYes, reconnect first
DownloadSometimesYes, with backoff
DownloadTimeoutYesYes, with longer timeout

§Example

use stem_rs::Error;

fn handle_error(err: Error) {
    match err {
        Error::Socket(io_err) => {
            eprintln!("Connection failed: {}", io_err);
            // Retry with exponential backoff
        }
        Error::Authentication(auth_err) => {
            eprintln!("Auth failed: {}", auth_err);
            // Check credentials or try different auth method
        }
        Error::Parse { location, reason } => {
            eprintln!("Parse error at {}: {}", location, reason);
            // Log and skip this descriptor
        }
        Error::OperationFailed { code, message } => {
            eprintln!("Tor rejected request: {} - {}", code, message);
            // Check if operation can be retried
        }
        _ => eprintln!("Error: {}", err),
    }
}

Variants§

§

Socket(Error)

I/O error during socket communication.

This error wraps standard I/O errors that occur during socket operations. Common causes include connection refused, connection reset, and network unreachable errors.

§Recovery

  • Check if Tor is running and the control port is accessible
  • Retry with exponential backoff for transient network issues
  • Verify firewall rules allow the connection
§

Protocol(String)

Malformed data received from the control protocol.

This indicates the data received from Tor doesn’t conform to the expected control protocol format. This typically indicates a bug in either Tor or this library.

§Recovery

This error is not recoverable. Report the issue with the malformed data.

§

Authentication(AuthError)

Authentication with Tor failed.

See AuthError for specific authentication failure reasons.

§Recovery

  • Check credentials (password, cookie file path)
  • Verify Tor’s authentication configuration
  • Try a different authentication method
§

OperationFailed

Tor was unable to complete the requested operation.

This error is returned when Tor understands the request but cannot fulfill it. The error code and message provide details about why.

§Fields

  • code: The numeric error code from Tor (e.g., “552”)
  • message: Human-readable error description from Tor

§Recovery

Check the error code to determine if retry is meaningful:

  • 4xx codes: Client error, fix the request
  • 5xx codes: Server error, may be transient

Fields

§code: String

The error code returned by Tor.

§message: String

The error message returned by Tor.

§

UnsatisfiableRequest(String)

The request cannot be satisfied with current Tor state.

This error indicates a valid request that Tor cannot fulfill due to its current state (e.g., requesting a circuit when Tor is not connected).

§Recovery

Wait for Tor to reach the required state, then retry.

§

InvalidRequest(String)

The request was malformed or invalid.

This indicates a programming error - the request doesn’t conform to the control protocol specification.

§Recovery

Fix the request format. This is not a transient error.

§

InvalidArguments(String)

The request contained invalid arguments.

Similar to InvalidRequest, but specifically for argument validation failures.

§Recovery

Fix the arguments. This is not a transient error.

§

Parse

Failed to parse a descriptor or other structured data.

This error occurs when parsing Tor descriptors (server descriptors, consensus documents, etc.) and the data doesn’t match the expected format.

§Fields

  • location: Where in the data the parse error occurred
  • reason: Description of what was expected vs. found

§Recovery

This error is not recoverable for the specific descriptor. Log the error and skip to the next descriptor if processing multiple.

Fields

§location: String

Location in the data where parsing failed.

§reason: String

Description of the parse failure.

§

Download

Failed to download a resource from the network.

This error occurs when downloading descriptors or other data from directory authorities or mirrors.

§Fields

  • url: The URL that failed to download
  • reason: Description of the failure

§Recovery

  • Retry with exponential backoff
  • Try a different directory authority or mirror

Fields

§url: String

The URL that failed to download.

§reason: String

The reason for the download failure.

§

DownloadTimeout

Download timed out before completing.

The configured timeout was reached before the download completed.

§Recovery

  • Increase the timeout value
  • Try a different server
  • Check network connectivity

Fields

§url: String

The URL that timed out.

§

Timeout

A general operation timeout occurred.

The operation did not complete within the expected time.

§Recovery

  • Increase timeout if configurable
  • Check if Tor is responsive
  • Retry the operation
§

SocketClosed

The control socket was closed unexpectedly.

This indicates the connection to Tor was lost. This can happen if Tor exits, the network connection is interrupted, or the socket is closed from the other end.

§Recovery

Reconnect to Tor and re-authenticate.

§

DescriptorUnavailable(String)

The requested descriptor is not available.

Tor doesn’t have the requested descriptor cached and cannot retrieve it.

§Recovery

  • Wait and retry (descriptor may become available)
  • Try downloading from a different source
§

CircuitExtensionFailed(String)

Failed to extend or create a circuit.

The circuit could not be built through the requested relays.

§Recovery

  • Try different relays
  • Wait for network conditions to improve
  • Check if the target relay is online
§

AddrParse(AddrParseError)

Failed to parse a socket address.

This error occurs when parsing a string into a socket address fails.

§Recovery

Verify the address format is correct (e.g., “127.0.0.1:9051”).

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

Source§

fn from(source: AddrParseError) -> Self

Converts to this type from the input type.
Source§

impl From<AuthError> for Error

Source§

fn from(source: AuthError) -> 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.

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.