tiempo-rs/src/error.rs

102 lines
2.9 KiB
Rust

use std::result;
use std::path::PathBuf;
use thiserror::Error;
use chrono::NaiveDateTime;
#[derive(Debug, Error)]
pub enum Error {
#[error("The subcommand '{0}' is not implemented")]
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 :(")]
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},
#[error("Could not understand '{0}' as a date format. Some options are:
Something similar to ISO format will be parsed as a time in the computer's
timezone.
* '2021-01-13' a date
* '2019-05-03 11:13' a date with portions of a time
ISO format with offset or UTC will be parsed as a time in the specified
timezone. Use 'Z' for 'UTC' and an offset for everything else
* '2021-01-13Z'
* '2005-10-14 19:20:35+05:00'
something that looks like an hour will be parsed as a time in the current
day in the computer's timezone. Add 'Z' or an offset to specify the timezone.
* '11:30'
* '23:50:45' (with seconds)
some human times, for now restricted to time ago:
* 'an hour ago'
* 'a minute ago'
* '50 min ago'
* '1h30m ago'
* 'two hours thirty minutes ago'")]
DateTimeParseError(String),
#[error("IOError: {0}")]
IOError(#[from] std::io::Error),
#[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")]
NoneLocalTime(String),
#[error("Trying to parse {orig} as a time in your timezone led to the ambiguous results {t1} and {t2}")]
AmbiguousLocalTime {
orig: String,
t1: NaiveDateTime,
t2: NaiveDateTime,
},
#[error("The provided regex '{0}' could not be parsed")]
InvalidRegex(String),
#[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,
},
}
pub type Result<T> = result::Result<T, Error>;