@@ -58,7 +58,8 @@ const DATE_LEN: usize = 10;
5858
5959fn parse_time_part ( buf : & [ u8 ] , size : usize ) -> Result < u32 > {
6060 if size > 0 && size < 3 {
61- Ok ( lexical_core:: FromLexical :: from_lexical ( buf) . unwrap ( ) )
61+ Ok ( lexical_core:: FromLexical :: from_lexical ( buf)
62+ . map_err_to_code ( ErrorCode :: BadBytes , || "time part parse error" . to_string ( ) ) ?)
6263 } else {
6364 let msg = format ! (
6465 "err with parse time part. Format like this:[03:00:00], got {} digits" ,
@@ -132,7 +133,7 @@ where T: AsRef<[u8]>
132133 match n {
133134 2 => {
134135 let hour_offset: i32 =
135- lexical_core:: FromLexical :: from_lexical ( buf. as_slice ( ) ) . unwrap ( ) ;
136+ lexical_core:: FromLexical :: from_lexical ( buf. as_slice ( ) ) . map_err_to_code ( ErrorCode :: BadBytes , || "hour offset parse error" . to_string ( ) ) ? ;
136137 if ( 0 ..15 ) . contains ( & hour_offset) {
137138 buf. clear ( ) ;
138139 if self . ignore_byte ( b':' ) {
@@ -143,7 +144,7 @@ where T: AsRef<[u8]>
143144 ) ) ;
144145 }
145146 let minute_offset: i32 =
146- lexical_core:: FromLexical :: from_lexical ( buf. as_slice ( ) ) . unwrap ( ) ;
147+ lexical_core:: FromLexical :: from_lexical ( buf. as_slice ( ) ) . map_err_to_code ( ErrorCode :: BadBytes , || "minute offset parse error" . to_string ( ) ) ? ;
147148 // max utc: 14:00, min utc: 00:00
148149 get_hour_minute_offset (
149150 tz,
@@ -166,10 +167,10 @@ where T: AsRef<[u8]>
166167 4 => {
167168 let hour_offset = & buf. as_slice ( ) [ ..2 ] ;
168169 let hour_offset: i32 =
169- lexical_core:: FromLexical :: from_lexical ( hour_offset) . unwrap ( ) ;
170+ lexical_core:: FromLexical :: from_lexical ( hour_offset) . map_err_to_code ( ErrorCode :: BadBytes , || "hour offset parse error" . to_string ( ) ) ? ;
170171 let minute_offset = & buf. as_slice ( ) [ 2 ..] ;
171172 let minute_offset: i32 =
172- lexical_core:: FromLexical :: from_lexical ( minute_offset) . unwrap ( ) ;
173+ lexical_core:: FromLexical :: from_lexical ( minute_offset) . map_err_to_code ( ErrorCode :: BadBytes , || "minute offset parse error" . to_string ( ) ) ? ;
173174 buf. clear ( ) ;
174175 // max utc: 14:00, min utc: 00:00
175176 if ( 0 ..15 ) . contains ( & hour_offset) {
@@ -257,8 +258,10 @@ where T: AsRef<[u8]>
257258 "Microsecond Parsing Error: Expecting a format like [.123456] for microseconds part" ,
258259 ) ) ;
259260 }
260- let mut scales: u64 =
261- lexical_core:: FromLexical :: from_lexical ( buf. as_slice ( ) ) . unwrap ( ) ;
261+ let mut scales: u64 = lexical_core:: FromLexical :: from_lexical ( buf. as_slice ( ) )
262+ . map_err_to_code ( ErrorCode :: BadBytes , || {
263+ "datetime scales parse error" . to_string ( )
264+ } ) ?;
262265 if size <= 9 {
263266 scales *= 10_u64 . pow ( 9 - size as u32 )
264267 } else {
0 commit comments