From 6603c46b41c1e154cd324ee72cebcb6b03f7b8cb Mon Sep 17 00:00:00 2001 From: Eirik Bjoroen Date: Sun, 7 May 2023 18:36:06 +0200 Subject: [PATCH 1/3] Changed what type of error gets reported --- vm/src/stdlib/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index 0f9f9e0bf1..51537685bb 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -350,7 +350,7 @@ mod time { } fn to_date_time(&self, vm: &VirtualMachine) -> PyResult { - let invalid = || vm.new_value_error("invalid struct_time parameter".to_owned()); + let invalid = || vm.new_overflow_error("invalid struct_time parameter".to_owned()); macro_rules! field { ($field:ident) => { self.$field.clone().try_into_value(vm)? From 3d9fb36cde37e4c9b5ae63f79a980ebdb743e418 Mon Sep 17 00:00:00 2001 From: Eirik Bjoroen Date: Sun, 7 May 2023 18:46:48 +0200 Subject: [PATCH 2/3] Changed what error message is shown --- vm/src/stdlib/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index 51537685bb..f804a9aa9f 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -350,7 +350,7 @@ mod time { } fn to_date_time(&self, vm: &VirtualMachine) -> PyResult { - let invalid = || vm.new_overflow_error("invalid struct_time parameter".to_owned()); + let invalid = || vm.new_overflow_error("mktime argument out of range".to_owned()); macro_rules! field { ($field:ident) => { self.$field.clone().try_into_value(vm)? From fa30d33c9bf15222e1bbd55959032c756044282b Mon Sep 17 00:00:00 2001 From: Eirik Bjoroen Date: Mon, 8 May 2023 20:52:23 +0200 Subject: [PATCH 3/3] Added both errors, and used value error for year, month, day and overflow for hour, min and sec - test now passes --- vm/src/stdlib/time.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index f804a9aa9f..3df9a04c12 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -350,7 +350,10 @@ mod time { } fn to_date_time(&self, vm: &VirtualMachine) -> PyResult { - let invalid = || vm.new_overflow_error("mktime argument out of range".to_owned()); + let invalid_overflow = + || vm.new_overflow_error("mktime argument out of range".to_owned()); + let invalid_value = || vm.new_value_error("invalid struct_time parameter".to_owned()); + macro_rules! field { ($field:ident) => { self.$field.clone().try_into_value(vm)? @@ -358,9 +361,9 @@ mod time { } let dt = NaiveDateTime::new( NaiveDate::from_ymd_opt(field!(tm_year), field!(tm_mon), field!(tm_mday)) - .ok_or_else(invalid)?, + .ok_or_else(invalid_value)?, NaiveTime::from_hms_opt(field!(tm_hour), field!(tm_min), field!(tm_sec)) - .ok_or_else(invalid)?, + .ok_or_else(invalid_overflow)?, ); Ok(dt) }