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

chore: address Rust 1.72 clippy lints #2011

Merged
merged 13 commits into from
Aug 28, 2023
4 changes: 4 additions & 0 deletions crates/data_models/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
pub type StorageResult<T> = error_stack::Result<T, StorageError>;

#[derive(Debug, thiserror::Error)]
pub enum StorageError {
#[error("Initialization Error")]
InitializationError,
// TODO: deprecate this error type to use a domain error instead
#[error("DatabaseError: {0:?}")]
DatabaseError(String),
Expand Down
4 changes: 4 additions & 0 deletions crates/drainer/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub async fn redis_connection(
.expect("Failed to create Redis connection Pool")
}

// TODO: use stores defined in storage_impl instead
/// # Panics
///
/// Will panic if could not create a db pool
#[allow(clippy::expect_used)]
pub async fn diesel_make_pg_pool(
database: &Database,
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;

pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;

///
/// # Panics
///
/// Panics if failed to create a redis pool
#[allow(clippy::expect_used)]
pub async fn redis_connection(
conf: &crate::configs::settings::Settings,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ impl api::FileUpload for Checkout {
match purpose {
api::FilePurpose::DisputeEvidence => {
let supported_file_types =
vec!["image/jpeg", "image/jpg", "image/png", "application/pdf"];
["image/jpeg", "image/jpg", "image/png", "application/pdf"];
// 4 Megabytes (MB)
if file_size > 4000000 {
Err(errors::ConnectorError::FileValidationFailed {
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ impl api::FileUpload for Stripe {
) -> CustomResult<(), errors::ConnectorError> {
match purpose {
api::FilePurpose::DisputeEvidence => {
let supported_file_types = vec!["image/jpeg", "image/png", "application/pdf"];
let supported_file_types = ["image/jpeg", "image/png", "application/pdf"];
// 5 Megabytes (MB)
if file_size > 5000000 {
Err(errors::ConnectorError::FileValidationFailed {
Expand Down
6 changes: 1 addition & 5 deletions crates/router/src/core/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,7 @@ pub mod error_stack_parsing {
attachments: current_error.attachments,
}]
.into_iter()
.chain(
Into::<VecLinearErrorStack<'a>>::into(current_error.sources)
.0
.into_iter(),
)
.chain(Into::<VecLinearErrorStack<'a>>::into(current_error.sources).0)
})
.collect();
Self(multi_layered_errors)
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ pub fn get_banks(

fn get_val(str: String, val: &serde_json::Value) -> Option<String> {
str.split('.')
.fold(Some(val), |acc, x| acc.and_then(|v| v.get(x)))
.try_fold(val, |acc, x| acc.get(x))
.and_then(|v| v.as_str())
.map(|s| s.to_string())
}
Expand Down
10 changes: 6 additions & 4 deletions crates/router/src/core/payments/operations/payment_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ pub async fn get_payment_intent_payment_attempt(
merchant_id: &str,
storage_scheme: enums::MerchantStorageScheme,
) -> RouterResult<(storage::PaymentIntent, storage::PaymentAttempt)> {
(|| async {
let get_pi_pa = || async {
let (pi, pa);
match payment_id {
api_models::payments::PaymentIdType::PaymentIntentId(ref id) => {
Expand Down Expand Up @@ -501,7 +501,9 @@ pub async fn get_payment_intent_payment_attempt(
}
}
error_stack::Result::<_, errors::DataStorageError>::Ok((pi, pa))
})()
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
};

get_pi_pa()
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
}
2 changes: 1 addition & 1 deletion crates/router/src/core/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ pub async fn sync_refund_with_gateway_workflow(
},
)
.await?;
let terminal_status = vec![
let terminal_status = [
enums::RefundStatus::Success,
enums::RefundStatus::Failure,
enums::RefundStatus::TransactionFailure,
Expand Down
9 changes: 6 additions & 3 deletions crates/router/src/db/configs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use diesel_models::configs::ConfigUpdateInternal;
use error_stack::IntoReport;
use error_stack::{IntoReport, ResultExt};
use storage_impl::redis::{
cache::{CacheKind, CONFIG_CACHE},
kv_store::RedisConnInterface,
Expand Down Expand Up @@ -126,8 +126,11 @@ impl ConfigInterface for MockDb {
let mut configs = self.configs.lock().await;

let config_new = storage::Config {
#[allow(clippy::as_conversions)]
id: configs.len() as i32,
id: configs
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
key: config.key,
config: config.config,
};
Expand Down
9 changes: 6 additions & 3 deletions crates/router/src/db/connector_response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use error_stack::IntoReport;
use error_stack::{IntoReport, ResultExt};

use super::{MockDb, Store};
use crate::{
Expand Down Expand Up @@ -88,8 +88,11 @@ impl ConnectorResponseInterface for MockDb {
) -> CustomResult<storage::ConnectorResponse, errors::StorageError> {
let mut connector_response = self.connector_response.lock().await;
let response = storage::ConnectorResponse {
#[allow(clippy::as_conversions)]
id: connector_response.len() as i32,
id: connector_response
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
payment_id: new.payment_id,
merchant_id: new.merchant_id,
attempt_id: new.attempt_id,
Expand Down
9 changes: 6 additions & 3 deletions crates/router/src/db/dispute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use error_stack::IntoReport;
use error_stack::{IntoReport, ResultExt};

use super::{MockDb, Store};
use crate::{
Expand Down Expand Up @@ -147,8 +147,11 @@ impl DisputeInterface for MockDb {
let now = common_utils::date_time::now();

let new_dispute = storage::Dispute {
#[allow(clippy::as_conversions)]
id: locked_disputes.len() as i32,
id: locked_disputes
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
dispute_id: dispute.dispute_id,
amount: dispute.amount,
currency: dispute.currency,
Expand Down
9 changes: 6 additions & 3 deletions crates/router/src/db/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use error_stack::IntoReport;
use error_stack::{IntoReport, ResultExt};

use super::{MockDb, Store};
use crate::{
Expand Down Expand Up @@ -52,8 +52,11 @@ impl EventInterface for MockDb {
let now = common_utils::date_time::now();

let stored_event = storage::Event {
#[allow(clippy::as_conversions)]
id: locked_events.len() as i32,
id: locked_events
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
event_id: event.event_id,
event_type: event.event_type,
event_class: event.event_class,
Expand Down
9 changes: 6 additions & 3 deletions crates/router/src/db/locker_mock_up.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use error_stack::IntoReport;
use error_stack::{IntoReport, ResultExt};

use super::{MockDb, Store};
use crate::{
Expand Down Expand Up @@ -84,8 +84,11 @@ impl LockerMockUpInterface for MockDb {
}

let created_locker = storage::LockerMockUp {
#[allow(clippy::as_conversions)]
id: locked_lockers.len() as i32,
id: locked_lockers
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
card_id: new.card_id,
external_id: new.external_id,
card_fingerprint: new.card_fingerprint,
Expand Down
9 changes: 6 additions & 3 deletions crates/router/src/db/mandate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use error_stack::IntoReport;
use error_stack::{IntoReport, ResultExt};

use super::{MockDb, Store};
use crate::{
Expand Down Expand Up @@ -221,8 +221,11 @@ impl MandateInterface for MockDb {
) -> CustomResult<storage::Mandate, errors::StorageError> {
let mut mandates = self.mandates.lock().await;
let mandate = storage::Mandate {
#[allow(clippy::as_conversions)]
id: mandates.len() as i32,
id: mandates
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
mandate_id: mandate_new.mandate_id.clone(),
customer_id: mandate_new.customer_id,
merchant_id: mandate_new.merchant_id,
Expand Down
7 changes: 5 additions & 2 deletions crates/router/src/db/merchant_connector_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,11 @@ impl MerchantConnectorAccountInterface for MockDb {
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
let mut accounts = self.merchant_connector_accounts.lock().await;
let account = storage::MerchantConnectorAccount {
#[allow(clippy::as_conversions)]
id: accounts.len() as i32,
id: accounts
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
merchant_id: t.merchant_id,
connector_name: t.connector_name,
connector_account_details: t.connector_account_details.into(),
Expand Down
8 changes: 6 additions & 2 deletions crates/router/src/db/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use data_models::payments::payment_intent::{
use data_models::payments::{
payment_attempt::PaymentAttempt, payment_intent::PaymentIntentFetchConstraints,
};
use error_stack::{IntoReport, ResultExt};

use super::MockDb;
#[cfg(feature = "olap")]
Expand Down Expand Up @@ -56,8 +57,11 @@ impl PaymentIntentInterface for MockDb {
let mut payment_intents = self.payment_intents.lock().await;
let time = common_utils::date_time::now();
let payment_intent = PaymentIntent {
#[allow(clippy::as_conversions)]
id: payment_intents.len() as i32,
id: payment_intents
.len()
.try_into()
.into_report()
.change_context(errors::DataStorageError::MockDbError)?,
payment_id: new.payment_id,
merchant_id: new.merchant_id,
status: new.status,
Expand Down
9 changes: 6 additions & 3 deletions crates/router/src/db/payment_method.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use diesel_models::payment_method::PaymentMethodUpdateInternal;
use error_stack::IntoReport;
use error_stack::{IntoReport, ResultExt};

use super::{MockDb, Store};
use crate::{
Expand Down Expand Up @@ -134,8 +134,11 @@ impl PaymentMethodInterface for MockDb {
let mut payment_methods = self.payment_methods.lock().await;

let payment_method = storage::PaymentMethod {
#[allow(clippy::as_conversions)]
id: payment_methods.len() as i32,
id: payment_methods
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
customer_id: payment_method_new.customer_id,
merchant_id: payment_method_new.merchant_id,
payment_method_id: payment_method_new.payment_method_id,
Expand Down
8 changes: 6 additions & 2 deletions crates/router/src/db/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::collections::HashSet;

use diesel_models::{errors::DatabaseError, refund::RefundUpdateInternal};
use error_stack::{IntoReport, ResultExt};

use super::MockDb;
use crate::{
Expand Down Expand Up @@ -735,8 +736,11 @@ impl RefundInterface for MockDb {
let current_time = common_utils::date_time::now();

let refund = storage_types::Refund {
#[allow(clippy::as_conversions)]
id: refunds.len() as i32,
id: refunds
.len()
.try_into()
.into_report()
.change_context(errors::StorageError::MockDbError)?,
internal_reference_id: new.internal_reference_id,
refund_id: new.refund_id,
payment_id: new.payment_id,
Expand Down
13 changes: 9 additions & 4 deletions crates/router/src/routes/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ impl AppStateInfo for AppState {
}

impl AppState {
/// # Panics
///
/// Panics if Store can't be created or JWE decryption fails
pub async fn with_storage(
conf: settings::Settings,
storage_impl: StorageImpl,
Expand All @@ -68,9 +71,12 @@ impl AppState {
let kms_client = kms::get_kms_client(&conf.kms).await;
let testable = storage_impl == StorageImpl::PostgresqlTest;
let store: Box<dyn StorageInterface> = match storage_impl {
StorageImpl::Postgresql | StorageImpl::PostgresqlTest => {
Box::new(get_store(&conf, shut_down_signal, testable).await)
}
StorageImpl::Postgresql | StorageImpl::PostgresqlTest => Box::new(
#[allow(clippy::expect_used)]
get_store(&conf, shut_down_signal, testable)
.await
.expect("Failed to create store"),
),
StorageImpl::Mock => Box::new(MockDb::new(&conf).await),
};

Expand All @@ -84,7 +90,6 @@ impl AppState {
.expect("Failed while performing KMS decryption");

#[cfg(feature = "email")]
#[allow(clippy::expect_used)]
let email_client = Box::new(AwsSes::new(&conf.email).await);
Self {
flow_name: String::from("default"),
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/scheduler/workflows/payment_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ProcessTrackerWorkflow for PaymentsSyncWorkflow {
)
.await?;

let terminal_status = vec![
let terminal_status = [
enums::AttemptStatus::RouterDeclined,
enums::AttemptStatus::Charged,
enums::AttemptStatus::AutoRefunded,
Expand Down
Loading