2020-04-13 22:03:06 +02:00
|
|
|
use crate::request::TimelineErr;
|
2020-04-01 21:35:24 +02:00
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum RedisConnErr {
|
|
|
|
ConnectionErr { addr: String, inner: std::io::Error },
|
|
|
|
InvalidRedisReply(String),
|
|
|
|
UnknownRedisErr(std::io::Error),
|
|
|
|
IncorrectPassword(String),
|
|
|
|
MissingPassword,
|
|
|
|
NotRedis(String),
|
2020-04-11 04:36:03 +02:00
|
|
|
TimelineErr(TimelineErr),
|
2020-04-01 21:35:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl RedisConnErr {
|
2020-04-21 22:39:31 +02:00
|
|
|
pub(crate) fn with_addr<T: AsRef<str>>(address: T, inner: std::io::Error) -> Self {
|
2020-04-01 21:35:24 +02:00
|
|
|
Self::ConnectionErr {
|
|
|
|
addr: address.as_ref().to_string(),
|
|
|
|
inner,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for RedisConnErr {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
|
|
|
use RedisConnErr::*;
|
|
|
|
let msg = match self {
|
|
|
|
ConnectionErr { addr, inner } => format!(
|
|
|
|
"Error connecting to Redis at {}.\n\
|
|
|
|
Connection Error: {}",
|
|
|
|
addr, inner
|
|
|
|
),
|
|
|
|
InvalidRedisReply(unexpected_reply) => format!(
|
|
|
|
"Received and unexpected reply from Redis. Expected `+PONG` reply but got `{}`",
|
|
|
|
unexpected_reply
|
|
|
|
),
|
|
|
|
UnknownRedisErr(io_err) => {
|
|
|
|
format!("Unexpected failure communicating with Redis: {}", io_err)
|
|
|
|
}
|
|
|
|
IncorrectPassword(attempted_password) => format!(
|
|
|
|
"Incorrect Redis password. You supplied `{}`.\n \
|
|
|
|
Please supply correct password with REDIS_PASSWORD environmental variable.",
|
|
|
|
attempted_password
|
|
|
|
),
|
|
|
|
MissingPassword => "Invalid authentication for Redis. Redis is configured to require \
|
|
|
|
a password, but you did not provide one. \n\
|
|
|
|
Set a password using the REDIS_PASSWORD environmental variable."
|
|
|
|
.to_string(),
|
|
|
|
NotRedis(addr) => format!(
|
|
|
|
"The server at {} is not a Redis server. Please update the REDIS_HOST and/or \
|
|
|
|
REDIS_PORT environmental variables and try again.",
|
|
|
|
addr
|
|
|
|
),
|
2020-04-11 04:36:03 +02:00
|
|
|
TimelineErr(inner) => format!("{}", inner),
|
2020-04-01 21:35:24 +02:00
|
|
|
};
|
|
|
|
write!(f, "{}", msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-11 04:36:03 +02:00
|
|
|
impl From<TimelineErr> for RedisConnErr {
|
|
|
|
fn from(e: TimelineErr) -> RedisConnErr {
|
|
|
|
RedisConnErr::TimelineErr(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 21:35:24 +02:00
|
|
|
impl From<std::io::Error> for RedisConnErr {
|
|
|
|
fn from(e: std::io::Error) -> RedisConnErr {
|
|
|
|
RedisConnErr::UnknownRedisErr(e)
|
|
|
|
}
|
|
|
|
}
|