fix(gateway): remove superflous redis error handling code that actually created more errors

This commit is contained in:
alyssa 2025-03-08 11:58:54 +00:00
parent 5fa9266d8d
commit ec49ead783
4 changed files with 2 additions and 23 deletions

View file

@ -3,7 +3,7 @@ use metrics::{counter, gauge};
use tracing::info;
use twilight_gateway::{Event, Latency};
use libpk::{state::*, util::redis::*};
use libpk::state::ShardState;
#[derive(Clone)]
pub struct ShardStateManager {
@ -24,11 +24,7 @@ impl ShardStateManager {
}
async fn get_shard(&self, shard_id: u32) -> anyhow::Result<ShardState> {
let data: Option<String> = self
.redis
.hget("pluralkit:shardstatus", shard_id)
.await
.to_option_or_error()?;
let data: Option<String> = self.redis.hget("pluralkit:shardstatus", shard_id).await?;
match data {
Some(buf) => Ok(serde_json::from_str(&buf).expect("could not decode shard data!")),
None => Ok(ShardState::default()),

View file

@ -9,7 +9,6 @@ use sentry_tracing::event_from_event;
pub mod db;
pub mod state;
pub mod util;
pub mod _config;
pub use crate::_config::CONFIG as config;

View file

@ -1 +0,0 @@
pub mod redis;

View file

@ -1,15 +0,0 @@
use fred::error::RedisError;
pub trait RedisErrorExt<T> {
fn to_option_or_error(self) -> Result<Option<T>, RedisError>;
}
impl<T> RedisErrorExt<T> for Result<T, RedisError> {
fn to_option_or_error(self) -> Result<Option<T>, RedisError> {
match self {
Ok(v) => Ok(Some(v)),
Err(error) if error.is_not_found() => Ok(None),
Err(error) => Err(error),
}
}
}