mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 03:36:03 +02:00
handle duration overflow error (#2616)
* handle duration overflow error * handle checked_add_signed result
This commit is contained in:
committed by
GitHub
parent
973a8ee8f3
commit
2b076369e0
@@ -199,9 +199,13 @@ pub fn compute_values(
|
||||
let result = match operator {
|
||||
Operator::Plus => {
|
||||
// FIXME: Not sure if I could do something better with the Span.
|
||||
let y = Primitive::into_chrono_duration(rhs.clone(), Span::unknown())
|
||||
.expect("Could not convert nushell Duration into chrono Duration.");
|
||||
Ok(x.checked_add_signed(y).expect("Data overflow."))
|
||||
match Primitive::into_chrono_duration(rhs.clone(), Span::unknown()) {
|
||||
Ok(y) => match x.checked_add_signed(y) {
|
||||
Some(value) => Ok(value),
|
||||
None => Err(("Date", "Duration and date addition overflow")),
|
||||
},
|
||||
Err(_) => Err(("Date", "Duration overflow")),
|
||||
}
|
||||
}
|
||||
_ => Err((left.type_name(), right.type_name())),
|
||||
}?;
|
||||
|
Reference in New Issue
Block a user