Skip to content

Commit

Permalink
fix: don't panic if the handshake wasn't performed - instead return a…
Browse files Browse the repository at this point in the history
…n error.

This makes the system more reliable, particularly when certain operations are
performed on Drop, and can happen prematurely.
  • Loading branch information
Byron committed Dec 11, 2024
1 parent 212ea9e commit d41cc0b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gix-transport/src/client/blocking_io/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl client::TransportWithoutIO for SpawnProcessOnDemand {
) -> Result<RequestWriter<'_>, 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)
}

Expand Down
2 changes: 1 addition & 1 deletion gix-transport/src/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl<H: Http> client::TransportWithoutIO for Transport<H> {
on_into_read: MessageKind,
trace: bool,
) -> Result<RequestWriter<'_>, 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),
Expand Down
2 changes: 2 additions & 0 deletions gix-transport/src/client/non_io_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit d41cc0b

Please sign in to comment.