Skip to content

Commit d41cc0b

Browse files
committed
fix: don't panic if the handshake wasn't performed - instead return an error.
This makes the system more reliable, particularly when certain operations are performed on Drop, and can happen prematurely.
1 parent 212ea9e commit d41cc0b

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

Diff for: gix-transport/src/client/blocking_io/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl client::TransportWithoutIO for SpawnProcessOnDemand {
109109
) -> Result<RequestWriter<'_>, client::Error> {
110110
self.connection
111111
.as_mut()
112-
.expect("handshake() to have been called first")
112+
.ok_or(client::Error::MissingHandshake)?
113113
.request(write_mode, on_into_read, trace)
114114
}
115115

Diff for: gix-transport/src/client/blocking_io/http/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<H: Http> client::TransportWithoutIO for Transport<H> {
333333
on_into_read: MessageKind,
334334
trace: bool,
335335
) -> Result<RequestWriter<'_>, client::Error> {
336-
let service = self.service.expect("handshake() must have been called first");
336+
let service = self.service.ok_or(client::Error::MissingHandshake)?;
337337
let url = append_url(&self.url, service.as_str());
338338
let static_headers = &[
339339
Cow::Borrowed(self.user_agent_header),

Diff for: gix-transport/src/client/non_io_types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ mod error {
112112
#[derive(thiserror::Error, Debug)]
113113
#[allow(missing_docs)]
114114
pub enum Error {
115+
#[error("A request was performed without performing the handshake first")]
116+
MissingHandshake,
115117
#[error("An IO error occurred when talking to the server")]
116118
Io(#[from] std::io::Error),
117119
#[error("Capabilities could not be parsed")]

0 commit comments

Comments
 (0)