diff --git a/crates/nu-data/src/value.rs b/crates/nu-data/src/value.rs index aaf259eb7e..e0c1897254 100644 --- a/crates/nu-data/src/value.rs +++ b/crates/nu-data/src/value.rs @@ -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())), }?; diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index eefb9dfb5a..e37edc196f 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -586,6 +586,31 @@ fn table_with_commas() { 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 { use nu_test_support::nu;