mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
handle duration overflow error (#2616)
* handle duration overflow error * handle checked_add_signed result
This commit is contained in:
parent
973a8ee8f3
commit
2b076369e0
2 changed files with 32 additions and 3 deletions
|
@ -199,9 +199,13 @@ pub fn compute_values(
|
||||||
let result = match operator {
|
let result = match operator {
|
||||||
Operator::Plus => {
|
Operator::Plus => {
|
||||||
// FIXME: Not sure if I could do something better with the Span.
|
// FIXME: Not sure if I could do something better with the Span.
|
||||||
let y = Primitive::into_chrono_duration(rhs.clone(), Span::unknown())
|
match Primitive::into_chrono_duration(rhs.clone(), Span::unknown()) {
|
||||||
.expect("Could not convert nushell Duration into chrono Duration.");
|
Ok(y) => match x.checked_add_signed(y) {
|
||||||
Ok(x.checked_add_signed(y).expect("Data overflow."))
|
Some(value) => Ok(value),
|
||||||
|
None => Err(("Date", "Duration and date addition overflow")),
|
||||||
|
},
|
||||||
|
Err(_) => Err(("Date", "Duration overflow")),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => Err((left.type_name(), right.type_name())),
|
_ => Err((left.type_name(), right.type_name())),
|
||||||
}?;
|
}?;
|
||||||
|
|
|
@ -586,6 +586,31 @@ fn table_with_commas() {
|
||||||
assert_eq!(actual.out, "141");
|
assert_eq!(actual.out, "141");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn duration_overflow() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: ".", pipeline(
|
||||||
|
r#"
|
||||||
|
ls | get modified | = $it + 1000000000000000000yr
|
||||||
|
"#)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(actual.err.contains("Duration overflow"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn date_and_duration_overflow() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: ".", pipeline(
|
||||||
|
r#"
|
||||||
|
ls | get modified | = $it + 1000000yr
|
||||||
|
"#)
|
||||||
|
);
|
||||||
|
|
||||||
|
// assert_eq!(actual.err, "overflow");
|
||||||
|
assert!(actual.err.contains("Duration and date addition overflow"));
|
||||||
|
}
|
||||||
|
|
||||||
mod parse {
|
mod parse {
|
||||||
use nu_test_support::nu;
|
use nu_test_support::nu;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue