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

fix: Print decimal value in error exception #2478

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading