Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone client: Improve connection errors. #854

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions glide-core/src/client/standalone_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct StandaloneClient {

pub enum StandaloneClientConnectionError {
NoAddressesProvided,
FailedConnection(Vec<(String, RedisError)>),
FailedConnection(Vec<(Option<String>, RedisError)>),
}

impl std::fmt::Debug for StandaloneClientConnectionError {
Expand All @@ -53,10 +53,29 @@ impl std::fmt::Debug for StandaloneClientConnectionError {
write!(f, "No addresses provided")
}
StandaloneClientConnectionError::FailedConnection(errs) => {
writeln!(f, "Received errors:")?;
for (address, error) in errs {
writeln!(f, "{address}: {error}")?;
}
match errs.len() {
0 => {
writeln!(f, "Failed without explicit error")?;
}
1 => {
let (ref address, ref error) = errs[0];
match address {
Some(address) => {
writeln!(f, "Received error for address `{address}`: {error}")?
}
None => writeln!(f, "Received error: {error}")?,
}
}
_ => {
writeln!(f, "Received errors:")?;
for (address, error) in errs {
match address {
Some(address) => writeln!(f, "{address}: {error}")?,
None => writeln!(f, "{error}")?,
}
}
}
};
Ok(())
}
}
Expand Down Expand Up @@ -104,12 +123,21 @@ impl StandaloneClient {
}
Err((address, (connection, err))) => {
nodes.push(connection);
addresses_and_errors.push((address, err));
addresses_and_errors.push((Some(address), err));
}
}
}

let Some(primary_index) = primary_index else {
if addresses_and_errors.is_empty() {
addresses_and_errors.insert(
0,
(
None,
RedisError::from((redis::ErrorKind::ClientError, "No primary node found")),
),
)
};
return Err(StandaloneClientConnectionError::FailedConnection(
addresses_and_errors,
));
Expand Down
Loading