Skip to content

Commit 246bf5c

Browse files
committed
fix(router): fix compilation errors in configs and reverse lookups modules
1 parent 8234e1f commit 246bf5c

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

crates/router/src/db/configs.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use common_utils::ext_traits::AsyncExt;
22
use diesel_models::configs::ConfigUpdateInternal;
3-
use error_stack::ResultExt;
3+
use error_stack::{report, ResultExt};
44
use router_env::{instrument, tracing};
55
use storage_impl::redis::{
66
cache::{CacheKind, CONFIG_CACHE},
@@ -65,7 +65,10 @@ impl ConfigInterface for Store {
6565
config: storage::ConfigNew,
6666
) -> CustomResult<storage::Config, errors::StorageError> {
6767
let conn = connection::pg_connection_write(self).await?;
68-
config.insert(&conn).await.map_err(Into::into)
68+
config
69+
.insert(&conn)
70+
.await
71+
.map_err(|error| report!(errors::StorageError::from(error)))
6972
}
7073

7174
#[instrument(skip_all)]
@@ -77,7 +80,7 @@ impl ConfigInterface for Store {
7780
let conn = connection::pg_connection_write(self).await?;
7881
storage::Config::update_by_key(&conn, key, config_update)
7982
.await
80-
.map_err(Into::into)
83+
.map_err(|error| report!(errors::StorageError::from(error)))
8184
}
8285

8386
//update in DB and remove in redis and cache
@@ -101,7 +104,7 @@ impl ConfigInterface for Store {
101104
let conn = connection::pg_connection_write(self).await?;
102105
storage::Config::find_by_key(&conn, key)
103106
.await
104-
.map_err(Into::into)
107+
.map_err(|error| report!(errors::StorageError::from(error)))
105108
}
106109

107110
//check in cache, then redis then finally DB, and on the way back populate redis and cache
@@ -114,7 +117,7 @@ impl ConfigInterface for Store {
114117
let conn = connection::pg_connection_write(self).await?;
115118
storage::Config::find_by_key(&conn, key)
116119
.await
117-
.map_err(Into::into)
120+
.map_err(|error| report!(errors::StorageError::from(error)))
118121
};
119122
cache::get_or_populate_in_memory(self, key, find_config_by_key_from_db, &CONFIG_CACHE).await
120123
}
@@ -130,7 +133,7 @@ impl ConfigInterface for Store {
130133
let conn = connection::pg_connection_write(self).await?;
131134
match storage::Config::find_by_key(&conn, key)
132135
.await
133-
.map_err(Into::<errors::StorageError>::into)
136+
.map_err(|error| report!(errors::StorageError::from(error)))
134137
{
135138
Ok(a) => Ok(a),
136139
Err(err) => {
@@ -144,7 +147,7 @@ impl ConfigInterface for Store {
144147
}
145148
.insert(&conn)
146149
.await
147-
.map_err(Into::into)
150+
.map_err(|error| report!(errors::StorageError::from(error)))
148151
})
149152
.await
150153
} else {
@@ -165,7 +168,7 @@ impl ConfigInterface for Store {
165168
let conn = connection::pg_connection_write(self).await?;
166169
let deleted = storage::Config::delete_by_key(&conn, key)
167170
.await
168-
.map_err(Into::into)?;
171+
.map_err(|error| report!(errors::StorageError::from(error)))?;
169172

170173
self.get_redis_conn()
171174
.map_err(Into::<errors::StorageError>::into)?
@@ -187,10 +190,7 @@ impl ConfigInterface for MockDb {
187190
let mut configs = self.configs.lock().await;
188191

189192
let config_new = storage::Config {
190-
id: configs
191-
.len()
192-
.try_into()
193-
.change_context(errors::StorageError::MockDbError)?,
193+
id: i32::try_from(configs.len()).change_context(errors::StorageError::MockDbError)?,
194194
key: config.key,
195195
config: config.config,
196196
};

crates/router/src/db/reverse_lookup.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub trait ReverseLookupInterface {
2323

2424
#[cfg(not(feature = "kv_store"))]
2525
mod storage {
26-
use error_stack::ResultExt;
26+
use error_stack::report;
2727
use router_env::{instrument, tracing};
2828

2929
use super::{ReverseLookupInterface, Store};
@@ -45,7 +45,9 @@ mod storage {
4545
_storage_scheme: enums::MerchantStorageScheme,
4646
) -> CustomResult<ReverseLookup, errors::StorageError> {
4747
let conn = connection::pg_connection_write(self).await?;
48-
new.insert(&conn).await.map_err(Into::into)
48+
new.insert(&conn)
49+
.await
50+
.map_err(|error| report!(errors::StorageError::from(error)))
4951
}
5052

5153
#[instrument(skip_all)]
@@ -57,14 +59,14 @@ mod storage {
5759
let conn = connection::pg_connection_read(self).await?;
5860
ReverseLookup::find_by_lookup_id(id, &conn)
5961
.await
60-
.map_err(Into::into)
62+
.map_err(|error| report!(errors::StorageError::from(error)))
6163
}
6264
}
6365
}
6466

6567
#[cfg(feature = "kv_store")]
6668
mod storage {
67-
use error_stack::ResultExt;
69+
use error_stack::{report, ResultExt};
6870
use redis_interface::SetnxReply;
6971
use router_env::{instrument, tracing};
7072
use storage_impl::redis::kv_store::{kv_wrapper, KvOperation};
@@ -92,7 +94,9 @@ mod storage {
9294
match storage_scheme {
9395
enums::MerchantStorageScheme::PostgresOnly => {
9496
let conn = connection::pg_connection_write(self).await?;
95-
new.insert(&conn).await.map_err(Into::into)
97+
new.insert(&conn)
98+
.await
99+
.map_err(|error| report!(errors::StorageError::from(error)))
96100
}
97101
enums::MerchantStorageScheme::RedisKv => {
98102
let created_rev_lookup = ReverseLookup {
@@ -121,7 +125,8 @@ mod storage {
121125
Ok(SetnxReply::KeyNotSet) => Err(errors::StorageError::DuplicateValue {
122126
entity: "reverse_lookup",
123127
key: Some(created_rev_lookup.lookup_id.clone()),
124-
}),
128+
}
129+
.into()),
125130
Err(er) => Err(er).change_context(errors::StorageError::KVError),
126131
}
127132
}
@@ -138,7 +143,7 @@ mod storage {
138143
let conn = connection::pg_connection_read(self).await?;
139144
ReverseLookup::find_by_lookup_id(id, &conn)
140145
.await
141-
.map_err(Into::into)
146+
.map_err(|error| report!(errors::StorageError::from(error)))
142147
};
143148

144149
match storage_scheme {

0 commit comments

Comments
 (0)