From d8bcf690a4895d8d53d6a52dabe4133d668fa1ea Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 1 Dec 2021 13:34:21 +0100 Subject: [PATCH] Return error instead of panicking on unexpected EOF --- epp-client/src/connection/registry.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/epp-client/src/connection/registry.rs b/epp-client/src/connection/registry.rs index 1c09690..e9285b2 100644 --- a/epp-client/src/connection/registry.rs +++ b/epp-client/src/connection/registry.rs @@ -4,7 +4,7 @@ use rustls::{OwnedTrustAnchor, RootCertStore}; use std::convert::TryInto; use std::sync::Arc; use std::{error::Error, io as stdio, net::ToSocketAddrs}; -use std::{str, u32}; +use std::{io, str, u32}; use tokio::{io::AsyncReadExt, io::AsyncWriteExt, net::TcpStream}; use tokio_rustls::{client::TlsStream, rustls::ClientConfig, TlsConnector}; @@ -76,7 +76,11 @@ impl EppConnection { debug!("{}: Total read: {} bytes", self.registry, read_size); if read == 0 { - panic!("{}: Unexpected eof", self.registry) + return Err(io::Error::new( + io::ErrorKind::UnexpectedEof, + format!("{}: unexpected eof", self.registry), + ) + .into()); } else if read_size >= message_size { break; }