aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/ping.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-08-06 07:22:19 +0000
committerGitHub <noreply@github.com>2022-08-06 02:22:19 -0500
commit5a9fca0ca9cdb46f4b866781f219756c89e2293a (patch)
treeb006e28b91a181734fb9702bb6ec510f5b2af3df /azalea-client/src/ping.rs
parent1d48c3fe34edd4e2295f54bd3d79f81f58c38a8e (diff)
downloadazalea-drasl-5a9fca0ca9cdb46f4b866781f219756c89e2293a.tar.xz
Better errors (#14)
* make reading use thiserror * finish implementing all the error things * clippy warnings related to ok_or * fix some errors in other places * thiserror in more places * don't use closures in a couple places * errors in writing packet * rip backtraces * change some BufReadError::Custom to UnexpectedEnumVariant * Errors say what packet is bad * error on leftover data and fix it wasn't reading the properties for gameprofile
Diffstat (limited to 'azalea-client/src/ping.rs')
-rwxr-xr-xazalea-client/src/ping.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/azalea-client/src/ping.rs b/azalea-client/src/ping.rs
index e4acfc34..303fae74 100755
--- a/azalea-client/src/ping.rs
+++ b/azalea-client/src/ping.rs
@@ -1,6 +1,6 @@
///! Ping Minecraft servers.
use azalea_protocol::{
- connect::Connection,
+ connect::{Connection, ConnectionError},
packets::{
handshake::client_intention_packet::ClientIntentionPacket,
status::{
@@ -12,10 +12,24 @@ use azalea_protocol::{
},
resolver, ServerAddress,
};
+use std::io;
+use thiserror::Error;
+
+#[derive(Error, Debug)]
+pub enum PingError {
+ #[error("{0}")]
+ Resolver(#[from] resolver::ResolverError),
+ #[error("{0}")]
+ Connection(#[from] ConnectionError),
+ #[error("{0}")]
+ ReadPacket(#[from] azalea_protocol::read::ReadPacketError),
+ #[error("{0}")]
+ WritePacket(#[from] io::Error),
+}
pub async fn ping_server(
address: &ServerAddress,
-) -> Result<ClientboundStatusResponsePacket, String> {
+) -> Result<ClientboundStatusResponsePacket, PingError> {
let resolved_address = resolver::resolve_address(address).await?;
let mut conn = Connection::new(&resolved_address).await?;
@@ -30,13 +44,13 @@ pub async fn ping_server(
}
.get(),
)
- .await;
+ .await?;
let mut conn = conn.status();
// send the empty status request packet
- conn.write(ServerboundStatusRequestPacket {}.get()).await;
+ conn.write(ServerboundStatusRequestPacket {}.get()).await?;
- let packet = conn.read().await.unwrap();
+ let packet = conn.read().await?;
match packet {
ClientboundStatusPacket::ClientboundStatusResponsePacket(p) => Ok(p),