Skip to content

Commit

Permalink
Standalone client: Improve connection errors.
Browse files Browse the repository at this point in the history
1. Add explicit error if primary node wasn't found.
2. Change the error message format, depending on how many internal errors it contains.
  • Loading branch information
nihohit committed Jan 23, 2024
1 parent 47c034d commit cafcebc
Showing 1 changed file with 34 additions and 6 deletions.
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

0 comments on commit cafcebc

Please sign in to comment.