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 returnedInvalidResponse(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 JSONUtf8Error(FromUtf8Error)
UTF-8 conversion error.
This error occurs when the server response contains invalid UTF-8 sequences.
§Example
// Usually occurs when reading server responseBase64Error(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()))