Skip to content

Commit

Permalink
fix: Print decimal value in error exception
Browse files Browse the repository at this point in the history
  • Loading branch information
karolisg committed Apr 5, 2024
1 parent 6829bd6 commit 60c9ca3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
11 changes: 9 additions & 2 deletions dozer-ingestion/oracle/src/connector/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,18 @@ fn map_field(index: usize, field: &FieldDefinition, row: &Row) -> Result<Field,
.map_or(Field::Null, |value| Field::Float(OrderedFloat(value))),
(FieldType::Float, false) => Field::Float(OrderedFloat(row.get(index)?)),
(FieldType::Decimal, true) => match row.get::<_, Option<String>>(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<String>>(index)?
Expand Down
4 changes: 2 additions & 2 deletions dozer-ingestion/oracle/src/connector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})?))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dozer-sink-aerospike/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 60c9ca3

Please sign in to comment.