From f08397ab15239040605eed3d7d9623d17df9463f Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Fri, 1 Mar 2024 21:23:51 +0000 Subject: [PATCH] Fix build issue due to csv parsing --- src/csv_parser.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/csv_parser.rs b/src/csv_parser.rs index 463b50d..97951be 100644 --- a/src/csv_parser.rs +++ b/src/csv_parser.rs @@ -1,3 +1,4 @@ +use anyhow::anyhow; use chrono::{NaiveDate, NaiveTime}; use csv::StringRecord; use crate::utils::Result; @@ -19,10 +20,10 @@ mod headings { } fn parse_csv_row(row: StringRecord) -> Result { - let start_date = row.get(headings::START_DATE).unwrap(); - let start_time = row.get(headings::START_TIME).unwrap(); - let end_date = row.get(headings::END_DATE).unwrap(); - let end_time = row.get(headings::END_TIME).unwrap(); + let start_date = row.get(headings::START_DATE).ok_or(anyhow!("Missing start date in CSV"))?; + let start_time = row.get(headings::START_TIME).ok_or(anyhow!("Missing start time in CSV"))?; + let end_date = row.get(headings::END_DATE).ok_or(anyhow!("Missing end date in CSV"))?; + let end_time = row.get(headings::END_TIME).ok_or(anyhow!("Missing end time in CSV"))?; let start_time = NaiveTime::parse_from_str(start_time, "%H:%M:%S")?; let end_time = NaiveTime::parse_from_str(end_time, "%H:%M:%S")?; @@ -32,14 +33,16 @@ fn parse_csv_row(row: StringRecord) -> Result let start = start_date.and_time(start_time); let end = end_date.and_time(end_time); - let description = row.get(headings::DESCRIPTION)?; - let project_name = row.get(headings::PROJECT_NAME)?; - let client_name = row.get(headings::CLIENT_NAME)?; - let tags = row.get(headings::TAGS)?; - let task_name = row.get(headings::TASK_NAME)?; - let billable = match row.get(headings::BILLABLE)? { + let description = row.get(headings::DESCRIPTION).ok_or(anyhow!("Missing description in CSV"))?; + let project_name = row.get(headings::PROJECT_NAME).ok_or(anyhow!("Missing project name in CSV"))?; + let client_name = row.get(headings::CLIENT_NAME).ok_or(anyhow!("Missing client name in CSV"))?; + let tags = row.get(headings::TAGS).ok_or(anyhow!("Missing tags in CSV"))?; + let task_name = row.get(headings::TASK_NAME).ok_or(anyhow!("Missing task name in CSV"))?; + let billable = match row.get(headings::BILLABLE).ok_or(anyhow!("Missing billable in CSV"))? { "Yes" => true, "No" => false, _ => unimplemented!("Unknown billable value") }; + + unimplemented!("Refactor model to support non-json sources") }