From 7875f1d2558bbc5a7540f14211f997082a11ca8c Mon Sep 17 00:00:00 2001 From: doinkythederp Date: Thu, 7 Mar 2024 21:45:11 -0800 Subject: [PATCH] docs: update error messages --- src/bedrock.rs | 15 ++++++++++----- src/lib.rs | 5 +++-- src/protocol.rs | 27 +++++++++++++++------------ src/protocol/frame.rs | 24 +++++++++--------------- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/bedrock.rs b/src/bedrock.rs index d486ab2..bd7ca03 100644 --- a/src/bedrock.rs +++ b/src/bedrock.rs @@ -55,8 +55,8 @@ impl From for crate::JavaServerInfo { } } +/// Server MOTD string is missing information. #[derive(Debug, Snafu)] -#[snafu(display("Not enough motd components"))] pub struct ServerInfoParseError; impl FromStr for BedrockServerInfo { @@ -88,30 +88,35 @@ impl FromStr for BedrockServerInfo { #[derive(Debug, Snafu)] pub enum BedrockPingError { + /// Failed to parse address. #[snafu(display("Failed to parse address {address:?}: {source}"))] AddressParse { source: AddrParseError, address: String, backtrace: Backtrace, }, - #[snafu(display("Server did not respond"))] + /// The server did not respond to the ping request. NoResponse { backtrace: Backtrace }, + /// Failed to parse server info. #[snafu(display("Failed to parse server info: {source}"), context(false))] ServerInfoParse { source: ServerInfoParseError, backtrace: Backtrace, }, - #[snafu(display("io error: {source}"), context(false))] + /// I/O error. + #[snafu(display("I/O error: {source}"), context(false))] Io { source: std::io::Error, backtrace: Backtrace, }, - #[snafu(display("dns lookup failed for address `{address}`"))] + /// DNS lookup failed. + #[snafu(display("DNS lookup failed for address `{address}`"))] DNSLookupFailed { address: String, backtrace: Backtrace, }, - #[snafu(display("failed to open socket: {source}"))] + /// Failed to open socket. + #[snafu(display("Failed to open socket: {source}"))] ConnectFailed { source: std::io::Error, backtrace: Backtrace, diff --git a/src/lib.rs b/src/lib.rs index ac799b6..8b0e1b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,12 +21,13 @@ pub mod bedrock; #[cfg(feature = "simple")] #[derive(Snafu, Debug)] pub enum PingError { - #[snafu(display("connection failed: {source}"), context(false))] + /// Connection failed. + #[snafu(display("Connection failed: {source}"), context(false))] Protocol { #[snafu(backtrace)] source: crate::protocol::ProtocolError, }, - #[snafu(display("connection did not respond in time"))] + /// The connection did not finish in time. Timeout { backtrace: Backtrace }, } diff --git a/src/protocol.rs b/src/protocol.rs index ec5be4d..8590401 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -23,41 +23,44 @@ mod frame; #[derive(Snafu, Debug)] pub enum ProtocolError { - #[snafu(display("io error: {source}"), context(false))] + /// I/O error. + #[snafu(display("I/O error: {source}"), context(false))] Io { source: std::io::Error, backtrace: Backtrace, }, - #[snafu(display("failed to encode string as bytes: {source}"), context(false))] + /// Failed to encode string as bytes. + #[snafu(display("Failed to encode string as bytes: {source}"), context(false))] StringEncodeFailed { #[snafu(backtrace)] source: McStringError, }, - #[snafu(display( - "failed to send packet because it is too long (more than {} bytes)", - i32::MAX - ))] + /// Failed to send a packet because it was longer than the maximum i32. PacketTooLong { backtrace: Backtrace }, - #[snafu(display("connection closed unexpectedly"))] + /// Connection closed unexpectedly. ConnectionClosed { backtrace: Backtrace }, - #[snafu(display("failed to parse packet: {source}"), context(false))] + /// Failed to parse a packet. + #[snafu(display("Failed to parse a packet: {source}"), context(false))] ParseFailed { #[snafu(backtrace)] source: FrameError, }, - #[snafu(display("srv resolver creation failed: {source}"), context(false))] + /// Failed to resolve SRV record. + #[snafu(display("Failed to resolve SRV record: {source}"), context(false))] SrvResolveError { source: trust_dns_resolver::error::ResolveError, backtrace: Backtrace, }, - #[snafu(display("packet received out of order"))] + /// Packet received out of order. FrameOutOfOrder { backtrace: Backtrace }, - #[snafu(display("failed to parse server response: {source}"), context(false))] + /// Failed to parse JSON response. + #[snafu(display("Failed to parse JSON response: {source}"), context(false))] JsonParse { source: serde_json::Error, backtrace: Backtrace, }, - #[snafu(display("dns lookup failed for address `{address}`"))] + /// DNS lookup failed. + #[snafu(display("DNS lookup failed for address `{address}`."))] DNSLookupFailed { address: String, backtrace: Backtrace, diff --git a/src/protocol/frame.rs b/src/protocol/frame.rs index 1ab7fd6..6e9cc20 100644 --- a/src/protocol/frame.rs +++ b/src/protocol/frame.rs @@ -9,30 +9,24 @@ use crate::mc_string::{decode_mc_string, McStringError}; #[derive(Snafu, Debug)] pub enum FrameError { - #[snafu(display("frame is missing data"))] + /// Received an incomplete frame. Incomplete { backtrace: Backtrace }, - #[snafu(display("io error: {source}"), context(false))] + /// I/O error. + #[snafu(display("I/O error: {source}"), context(false))] Io { source: std::io::Error, backtrace: Backtrace, }, - #[snafu(display("frame declares it has negative length"))] + /// Received a frame with an invalid length. InvalidLength { backtrace: Backtrace }, - #[snafu(display("cannot parse frame with id {id}"))] - InvalidFrame { id: i32, backtrace: Backtrace }, - #[snafu(display("failed to decode string: {source}"), context(false))] + /// Received a frame with an invalid id. + InvalidFrameId { id: i32, backtrace: Backtrace }, + /// Failed to decode string. + #[snafu(display("Failed to decode string: {source}"), context(false))] StringDecodeFailed { #[snafu(backtrace)] source: McStringError, }, - #[snafu( - display("failed to decode ping response payload: {source}"), - context(false) - )] - PingResponseDecodeFailed { - source: TryFromSliceError, - backtrace: Backtrace, - }, } #[derive(Debug)] @@ -155,6 +149,6 @@ impl Frame { } } - InvalidFrameSnafu { id }.fail() + InvalidFrameIdSnafu { id }.fail() } }