diff --git a/gix-transport/src/client/blocking_io/file.rs b/gix-transport/src/client/blocking_io/file.rs index 8f0186c59aa..a145a305fab 100644 --- a/gix-transport/src/client/blocking_io/file.rs +++ b/gix-transport/src/client/blocking_io/file.rs @@ -109,7 +109,7 @@ impl client::TransportWithoutIO for SpawnProcessOnDemand { ) -> Result, client::Error> { self.connection .as_mut() - .expect("handshake() to have been called first") + .ok_or(client::Error::MissingHandshake)? .request(write_mode, on_into_read, trace) } diff --git a/gix-transport/src/client/blocking_io/http/mod.rs b/gix-transport/src/client/blocking_io/http/mod.rs index 5994c88c76e..503924e9690 100644 --- a/gix-transport/src/client/blocking_io/http/mod.rs +++ b/gix-transport/src/client/blocking_io/http/mod.rs @@ -333,7 +333,7 @@ impl client::TransportWithoutIO for Transport { on_into_read: MessageKind, trace: bool, ) -> Result, client::Error> { - let service = self.service.expect("handshake() must have been called first"); + let service = self.service.ok_or(client::Error::MissingHandshake)?; let url = append_url(&self.url, service.as_str()); let static_headers = &[ Cow::Borrowed(self.user_agent_header), diff --git a/gix-transport/src/client/non_io_types.rs b/gix-transport/src/client/non_io_types.rs index d4d6cc8c19b..24a69a57e21 100644 --- a/gix-transport/src/client/non_io_types.rs +++ b/gix-transport/src/client/non_io_types.rs @@ -112,6 +112,8 @@ mod error { #[derive(thiserror::Error, Debug)] #[allow(missing_docs)] pub enum Error { + #[error("A request was performed without performing the handshake first")] + MissingHandshake, #[error("An IO error occurred when talking to the server")] Io(#[from] std::io::Error), #[error("Capabilities could not be parsed")]