Skip to content

Commit 98f0a80

Browse files
authored
feat: include error message in ConnectError (#258)
Injects `cause` to the `ConnectError` display string. This allows for better error introspection in dependent packages. Unblocks apify/crawlee-python#1389
1 parent e573082 commit 98f0a80

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

impit-python/src/errors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ impl From<ImpitPyError> for pyo3::PyErr {
5656
ImpitPyError(ImpitError::WriteTimeout) => WriteTimeout::new_err(format!("{}", err.0)),
5757
ImpitPyError(ImpitError::PoolTimeout) => PoolTimeout::new_err(format!("{}", err.0)),
5858
ImpitPyError(ImpitError::NetworkError) => NetworkError::new_err(format!("{}", err.0)),
59-
ImpitPyError(ImpitError::ConnectError) => ConnectError::new_err(format!("{}", err.0)),
59+
ImpitPyError(ImpitError::ConnectError(_)) => {
60+
ConnectError::new_err(format!("{}", err.0))
61+
}
6062
ImpitPyError(ImpitError::ReadError) => ReadError::new_err(format!("{}", err.0)),
6163
ImpitPyError(ImpitError::WriteError) => WriteError::new_err(format!("{}", err.0)),
6264
ImpitPyError(ImpitError::CloseError) => CloseError::new_err(format!("{}", err.0)),

impit/src/errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ pub enum ImpitError {
3434
PoolTimeout,
3535
#[error("Network error occurred.")]
3636
NetworkError,
37-
#[error("Failed to connect to the server.")]
38-
ConnectError,
37+
#[error("Failed to connect to the server.\nReason: {0}")]
38+
ConnectError(String),
3939
#[error("Failed to read data from the server.")]
4040
ReadError,
4141
#[error("Failed to write data to the server.")]
@@ -107,17 +107,17 @@ impl ImpitError {
107107
.source()
108108
.and_then(|e| e.downcast_ref::<hyper_util::client::legacy::Error>())
109109
{
110-
if source_error.is_connect() {
111-
return ImpitError::ConnectError;
112-
}
113-
114110
if let Some(e) = source_error.source() {
115111
if let Some(hyper_error) = e.downcast_ref::<hyper::Error>() {
116112
if hyper_error.is_incomplete_message() {
117113
return ImpitError::RemoteProtocolError;
118114
}
119115
}
120116
}
117+
118+
if source_error.is_connect() {
119+
return ImpitError::ConnectError(format!("{source_error:#?}"));
120+
}
121121
}
122122
}
123123

0 commit comments

Comments
 (0)