handle the error of the malformed time in database
This commit is contained in:
parent
9d6a17b622
commit
faef02d0a9
|
@ -203,17 +203,30 @@ impl Database for SqliteDatabase {
|
||||||
fn entry_query(&self, query: &str, params: &[&dyn ToSql]) -> Result<Vec<Entry>> {
|
fn entry_query(&self, query: &str, params: &[&dyn ToSql]) -> Result<Vec<Entry>> {
|
||||||
let mut stmt = self.connection.prepare(query)?;
|
let mut stmt = self.connection.prepare(query)?;
|
||||||
|
|
||||||
let results = stmt.query_map(params, |row| {
|
let x = stmt.query_and_then(params, |row| {
|
||||||
Ok(Entry {
|
let id: u64 = row.get("id")?;
|
||||||
id: row.get("id")?,
|
let note = row.get("note")?;
|
||||||
note: row.get("note")?,
|
let sheet = row.get("sheet")?;
|
||||||
start: row.get("start")?,
|
|
||||||
end: row.get("end")?,
|
|
||||||
sheet: row.get("sheet")?,
|
|
||||||
})
|
|
||||||
})?.filter_map(|r| r.ok()).collect();
|
|
||||||
|
|
||||||
Ok(results)
|
let start = row.get("start").map_err(|_| {
|
||||||
|
Error::InvalidTimeInDatabase {
|
||||||
|
id: id.to_string(),
|
||||||
|
col: "start".into(),
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
let end = row.get("start").map_err(|_| {
|
||||||
|
Error::InvalidTimeInDatabase {
|
||||||
|
id: id.to_string(),
|
||||||
|
col: "start".into(),
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(Entry {
|
||||||
|
id, note, start, end, sheet,
|
||||||
|
})
|
||||||
|
})?.collect();
|
||||||
|
|
||||||
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
fn meta_query(&self, query: &str, params: &[&dyn ToSql]) -> Result<Vec<Meta>> {
|
fn meta_query(&self, query: &str, params: &[&dyn ToSql]) -> Result<Vec<Meta>> {
|
||||||
|
|
16
src/error.rs
16
src/error.rs
|
@ -54,6 +54,22 @@ pub enum Error {
|
||||||
|
|
||||||
#[error("Could not understand '{0}' as a month specifier. Try 'this', 'last', or any month name like 'january' or 'nov'")]
|
#[error("Could not understand '{0}' as a month specifier. Try 'this', 'last', or any month name like 'january' or 'nov'")]
|
||||||
InvalidMonthSpec(String),
|
InvalidMonthSpec(String),
|
||||||
|
|
||||||
|
#[error("An error ocurred while trying to read entries from the database.
|
||||||
|
|
||||||
|
In the row with id {id} the data at column '{col}' has a value that is not a
|
||||||
|
valid time.
|
||||||
|
|
||||||
|
A valid time looks like this: '2021-07-12 19:35:43.645916' and must be in UTC
|
||||||
|
timezone (unless you are using a database that was created by timetrap, case in
|
||||||
|
which the times are in the local timezone).
|
||||||
|
|
||||||
|
To fix this problem you can use t backend and manually update the value using
|
||||||
|
good old SQL.")]
|
||||||
|
InvalidTimeInDatabase {
|
||||||
|
id: String,
|
||||||
|
col: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
Loading…
Reference in New Issue