McError

Enum McError 

Source
pub enum McError {
    DnsError(String),
    ConnectionError(String),
    Timeout,
    InvalidResponse(String),
    IoError(Error),
    JsonError(Error),
    Utf8Error(FromUtf8Error),
    Base64Error(DecodeError),
    InvalidEdition(String),
    InvalidPort(String),
    InvalidAddress(String),
}
Expand description

Errors that can occur during Minecraft server status queries.

All errors implement std::error::Error and can be easily converted to user-friendly error messages using the Display trait.

§Error Types

  • DnsError: DNS resolution failed (e.g., hostname not found)
  • ConnectionError: Failed to establish connection to server
  • Timeout: Request timed out
  • InvalidResponse: Server returned invalid or malformed data
  • IoError: I/O error occurred (wrapped std::io::Error)
  • JsonError: Failed to parse JSON response (wrapped serde_json::Error)
  • Utf8Error: Invalid UTF-8 in server response
  • Base64Error: Failed to decode base64 data (e.g., favicon)
  • InvalidEdition: Invalid server edition specified
  • InvalidPort: Invalid port number in address
  • InvalidAddress: Invalid address format

Variants§

§

DnsError(String)

DNS resolution failed.

This error occurs when the hostname cannot be resolved to an IP address, or when an SRV record lookup fails.

§Example

Err(McError::DnsError("Hostname not found".to_string()))
§

ConnectionError(String)

Connection to server failed.

This error occurs when a TCP/UDP connection cannot be established, typically due to network issues or the server being unreachable.

§Example

Err(McError::ConnectionError("Connection refused".to_string()))
§

Timeout

Request timed out.

This error occurs when the server does not respond within the configured timeout duration. You can adjust the timeout using McClient::with_timeout.

§Example

let client = McClient::new().with_timeout(Duration::from_secs(2));
// If server doesn't respond within 2 seconds, Timeout error is returned
§

InvalidResponse(String)

Server returned invalid or malformed response.

This error occurs when the server response does not match the expected protocol format, or contains invalid data.

§Example

Err(McError::InvalidResponse("Response too short".to_string()))
§

IoError(Error)

I/O error occurred.

This is a wrapper around std::io::Error for operations like reading from or writing to network streams.

§Example

let io_error = io::Error::new(io::ErrorKind::NotFound, "File not found");
Err(McError::IoError(io_error))
§

JsonError(Error)

JSON parsing error.

This error occurs when the server response contains invalid JSON. It’s a wrapper around serde_json::Error.

§Example

// Usually occurs when parsing Java server status JSON
§

Utf8Error(FromUtf8Error)

UTF-8 conversion error.

This error occurs when the server response contains invalid UTF-8 sequences.

§Example

// Usually occurs when reading server response
§

Base64Error(DecodeError)

Base64 decoding error.

This error occurs when decoding base64-encoded data (e.g., server favicon) fails.

§Example

// Can occur when saving favicon
java.save_favicon("icon.png").unwrap();
§

InvalidEdition(String)

Invalid server edition specified.

This error occurs when an invalid server edition is provided. Valid editions are Java and Bedrock.

§Example

ServerEdition::from_str("invalid")?;
§

InvalidPort(String)

Invalid port number in address.

This error occurs when the port in the address string cannot be parsed as a valid u16 value.

§Example

let client = McClient::new();
// This will return InvalidPort error
let _ = client.ping("server.com:99999", ServerEdition::Java).await;
§

InvalidAddress(String)

Invalid address format.

This error occurs when the server address has an invalid format.

§Example

Err(McError::InvalidAddress("Invalid format".to_string()))

Trait Implementations§

Source§

impl Debug for McError

Source§

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

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

impl Display for McError

Source§

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

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

impl Error for McError

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<DecodeError> for McError

Source§

fn from(source: DecodeError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for McError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for McError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<FromUtf8Error> for McError

Source§

fn from(source: FromUtf8Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> Instrument for T

Source§

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

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

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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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