From 5a9fca0ca9cdb46f4b866781f219756c89e2293a Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sat, 6 Aug 2022 07:22:19 +0000 Subject: 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 --- azalea-protocol/src/resolver.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'azalea-protocol/src/resolver.rs') diff --git a/azalea-protocol/src/resolver.rs b/azalea-protocol/src/resolver.rs index 24687a6e..e21362a5 100755 --- a/azalea-protocol/src/resolver.rs +++ b/azalea-protocol/src/resolver.rs @@ -1,16 +1,24 @@ -use std::net::IpAddr; - use crate::{ServerAddress, ServerIpAddress}; use async_recursion::async_recursion; +use std::net::IpAddr; +use thiserror::Error; use trust_dns_resolver::{ config::{ResolverConfig, ResolverOpts}, TokioAsyncResolver, }; +#[derive(Error, Debug)] +pub enum ResolverError { + #[error("No SRV record found")] + NoSrvRecord, + #[error("No IP found")] + NoIp, +} + /// Resolve a Minecraft server address into an IP address and port. /// If it's already an IP address, it's returned as-is. #[async_recursion] -pub async fn resolve_address(address: &ServerAddress) -> Result { +pub async fn resolve_address(address: &ServerAddress) -> Result { // If the address.host is already in the format of an ip address, return it. if let Ok(ip) = address.host.parse::() { return Ok(ServerIpAddress { @@ -33,20 +41,20 @@ pub async fn resolve_address(address: &ServerAddress) -> Result