tiempo-rs/src/error.rs

76 lines
2.2 KiB
Rust
Raw Normal View History

2021-06-18 11:27:19 -05:00
use std::result;
use std::path::PathBuf;
use thiserror::Error;
use chrono::NaiveDateTime;
2021-06-18 11:27:19 -05:00
#[derive(Debug, Error)]
pub enum Error {
2021-07-13 09:11:51 -05:00
#[error("The subcommand '{0}' is not implemented")]
2021-06-18 11:27:19 -05:00
UnimplementedCommand(String),
#[error("Sqlite error: {0}")]
Sqlite(#[from] rusqlite::Error),
#[error("Could not find home directory or a place where configuration can be read an written :(")]
2021-06-18 11:27:19 -05:00
NoHomeDir,
#[error("The file {0} was not found")]
FileNotFound(PathBuf),
#[error("Error reading the file: {0}")]
CouldntRead(PathBuf),
#[error("Couldn't parse toml file at: {path}\nwith error: {error}")]
TomlError{ path: PathBuf, error: toml::de::Error},
#[error("Couldn't parse yaml file at: {path}\nwith error: {error}")]
YamlError{ path: PathBuf, error: serde_yaml::Error},
2021-06-21 11:12:30 -05:00
2021-07-01 23:42:59 -05:00
#[error("Could not understand '{0}' as a date format.")]
DateTimeParseError(String),
#[error("IOError: {0}")]
IOError(#[from] std::io::Error),
2021-06-30 18:51:34 -05:00
#[error("CSV Error: {0}")]
CSVError(#[from] csv::Error),
#[error("Corrupted data found in the database: {0}")]
CorruptedData(String),
#[error("Trying to parse {0} as a time in your timezone led to no results")]
2021-07-01 23:42:59 -05:00
NoneLocalTime(String),
#[error("Trying to parse {orig} as a time in your timezone led to the ambiguous results {t1} and {t2}")]
AmbiguousLocalTime {
2021-07-01 23:42:59 -05:00
orig: String,
2021-07-02 10:07:07 -05:00
t1: NaiveDateTime,
t2: NaiveDateTime,
2021-07-07 10:49:29 -05:00
},
#[error("The provided regex '{0}' could not be parsed")]
InvalidRegex(String),
2021-07-10 13:20:42 -05:00
#[error("Could not understand '{0}' as a month specifier. Try 'this', 'last', or any month name like 'january' or 'nov'")]
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,
},
2021-06-18 11:27:19 -05:00
}
pub type Result<T> = result::Result<T, Error>;