From 60c9ca335bb66f1350c3ce0469eb9b8c68504809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Gudi=C5=A1kis?= Date: Fri, 5 Apr 2024 20:30:59 +0530 Subject: [PATCH 1/2] fix: Print decimal value in error exception --- dozer-ingestion/oracle/src/connector/mapping.rs | 11 +++++++++-- dozer-ingestion/oracle/src/connector/mod.rs | 4 ++-- .../oracle/src/connector/replicate/transaction/map.rs | 6 +++++- .../src/connector/replicate/transaction/parse/mod.rs | 4 +++- dozer-sink-aerospike/src/lib.rs | 2 +- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/dozer-ingestion/oracle/src/connector/mapping.rs b/dozer-ingestion/oracle/src/connector/mapping.rs index e109cbbbfa..f452238f85 100644 --- a/dozer-ingestion/oracle/src/connector/mapping.rs +++ b/dozer-ingestion/oracle/src/connector/mapping.rs @@ -109,11 +109,18 @@ fn map_field(index: usize, field: &FieldDefinition, row: &Row) -> Result Field::Float(OrderedFloat(row.get(index)?)), (FieldType::Decimal, true) => match row.get::<_, Option>(index)? { - Some(decimal) => Field::Decimal(Decimal::from_str(&decimal)?), + Some(decimal) => Field::Decimal( + Decimal::from_str(&decimal) + .map_err(|e| crate::connector::Error::NumberToDecimal(e, decimal))?, + ), None => Field::Null, }, (FieldType::Decimal, false) => { - Field::Decimal(Decimal::from_str(&row.get::<_, String>(index)?)?) + let value = row.get::<_, String>(index)?; + Field::Decimal( + Decimal::from_str(&value) + .map_err(|e| crate::connector::Error::NumberToDecimal(e, value))?, + ) } (FieldType::String, true) => row .get::<_, Option>(index)? diff --git a/dozer-ingestion/oracle/src/connector/mod.rs b/dozer-ingestion/oracle/src/connector/mod.rs index 70ea0b617f..38164c3fd5 100644 --- a/dozer-ingestion/oracle/src/connector/mod.rs +++ b/dozer-ingestion/oracle/src/connector/mod.rs @@ -50,8 +50,8 @@ pub enum Error { }, #[error("column count mismatch: expected {expected}, actual {actual}")] ColumnCountMismatch { expected: usize, actual: usize }, - #[error("cannot convert Oracle number to decimal: {0}")] - NumberToDecimal(#[from] rust_decimal::Error), + #[error("cannot convert Oracle number to decimal: {0}. Value: {1:?}")] + NumberToDecimal(rust_decimal::Error, String), #[error("insert failed to match: {0}")] InsertFailedToMatch(String), #[error("delete failed to match: {0}")] diff --git a/dozer-ingestion/oracle/src/connector/replicate/transaction/map.rs b/dozer-ingestion/oracle/src/connector/replicate/transaction/map.rs index 122ce3b5f9..6b3d27dfd2 100644 --- a/dozer-ingestion/oracle/src/connector/replicate/transaction/map.rs +++ b/dozer-ingestion/oracle/src/connector/replicate/transaction/map.rs @@ -112,7 +112,11 @@ fn map_value( .to_f64() .ok_or_else(|| Error::FloatOverflow(number))?, ))), - (ParsedValue::String(string), FieldType::Decimal, _) => Ok(Field::Decimal(string.parse()?)), + (ParsedValue::String(string), FieldType::Decimal, _) => { + Ok(Field::Decimal(string.parse().map_err(|e| { + crate::connector::Error::NumberToDecimal(e, string) + })?)) + } (ParsedValue::Number(number), FieldType::Decimal, _) => Ok(Field::Decimal(number)), (ParsedValue::Number(number), FieldType::Int, _) => Ok(Field::Int( number diff --git a/dozer-ingestion/oracle/src/connector/replicate/transaction/parse/mod.rs b/dozer-ingestion/oracle/src/connector/replicate/transaction/parse/mod.rs index 1bbb371ab8..e8be03ebd4 100644 --- a/dozer-ingestion/oracle/src/connector/replicate/transaction/parse/mod.rs +++ b/dozer-ingestion/oracle/src/connector/replicate/transaction/parse/mod.rs @@ -130,7 +130,9 @@ impl FromStr for ParsedValue { if s.starts_with('\'') { Ok(ParsedValue::String(s[1..s.len() - 1].to_string())) } else { - Ok(ParsedValue::Number(s.parse()?)) + Ok(ParsedValue::Number(s.parse().map_err(|e| { + crate::connector::Error::NumberToDecimal(e, s.to_string()) + })?)) } } } diff --git a/dozer-sink-aerospike/src/lib.rs b/dozer-sink-aerospike/src/lib.rs index c28937932b..1b19bfa827 100644 --- a/dozer-sink-aerospike/src/lib.rs +++ b/dozer-sink-aerospike/src/lib.rs @@ -3,7 +3,7 @@ pub use crate::aerospike::Client; use aerospike_client_sys::*; use denorm_dag::DenormalizationState; use dozer_core::event::EventHub; -use dozer_types::log::error; +use dozer_types::log::{debug, error}; use dozer_types::models::connection::AerospikeConnection; use dozer_types::node::OpIdentifier; use dozer_types::thiserror; From 3de53a1146f8a102d6f3756d828ca0481117ce6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Gudi=C5=A1kis?= Date: Fri, 5 Apr 2024 20:36:11 +0530 Subject: [PATCH 2/2] Remove import --- dozer-sink-aerospike/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dozer-sink-aerospike/src/lib.rs b/dozer-sink-aerospike/src/lib.rs index 1b19bfa827..c28937932b 100644 --- a/dozer-sink-aerospike/src/lib.rs +++ b/dozer-sink-aerospike/src/lib.rs @@ -3,7 +3,7 @@ pub use crate::aerospike::Client; use aerospike_client_sys::*; use denorm_dag::DenormalizationState; use dozer_core::event::EventHub; -use dozer_types::log::{debug, error}; +use dozer_types::log::error; use dozer_types::models::connection::AerospikeConnection; use dozer_types::node::OpIdentifier; use dozer_types::thiserror;