From 9fa9c76a9cfb697fd00e87d8aaa272edcad73b17 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 5 Oct 2020 09:16:25 +0200 Subject: [PATCH] improve error messages in parse_rfc3339 Signed-off-by: Wolfgang Bumiller --- proxmox/src/tools/time/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/proxmox/src/tools/time/mod.rs b/proxmox/src/tools/time/mod.rs index 51f7f971..13940126 100644 --- a/proxmox/src/tools/time/mod.rs +++ b/proxmox/src/tools/time/mod.rs @@ -201,8 +201,8 @@ pub fn epoch_to_rfc3339(epoch: i64) -> Result { } /// Parse RFC3339 into Unix epoch -pub fn parse_rfc3339(i: &str) -> Result { - let input = i.as_bytes(); +pub fn parse_rfc3339(input_str: &str) -> Result { + let input = input_str.as_bytes(); let expect = |pos: usize, c: u8| { if input[pos] != c { @@ -227,24 +227,24 @@ pub fn parse_rfc3339(i: &str) -> Result { }; crate::try_block!({ - if i.len() < 20 || i.len() > 25 { - bail!("wrong length"); + if input.len() < 20 || input.len() > 25 { + bail!("timestamp of unexpected length"); } let tz = input[19]; match tz { b'Z' => { - if i.len() != 20 { - bail!("wrong length"); + if input.len() != 20 { + bail!("unexpected length in UTC timestamp"); } } b'+' | b'-' => { - if i.len() != 25 { - bail!("wrong length"); + if input.len() != 25 { + bail!("unexpected length in timestamp"); } } - _ => bail!("got unknown timezone indicator"), + _ => bail!("unexpected timezone indicator"), } let mut tm = TmEditor::new(true); @@ -282,7 +282,7 @@ pub fn parse_rfc3339(i: &str) -> Result { Ok(epoch) }) - .map_err(|err| format_err!("parse_rfc_3339 failed - {}", err)) + .map_err(|err| format_err!("failed to parse rfc3339 timestamp ({:?}) - {}", input_str, err)) } #[test]