Skip to main content

dejavu/
error.rs

1//! Typed error enums for the library. Binaries convert these at the boundary
2//! with `anyhow`.
3
4use std::path::PathBuf;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8pub enum PathError {
9    #[error("could not determine the home directory")]
10    NoHome,
11    #[error("could not determine the cache directory")]
12    NoCacheDir,
13    #[error("path is not writable: {0}")]
14    NotWritable(PathBuf),
15    #[error(transparent)]
16    Io(#[from] std::io::Error),
17}
18
19#[derive(Error, Debug)]
20pub enum ConfigError {
21    #[error(transparent)]
22    Io(#[from] std::io::Error),
23    #[error("failed to parse TOML config at {path}: {source}")]
24    Toml {
25        path: PathBuf,
26        source: toml::de::Error,
27    },
28    #[error(transparent)]
29    Json(#[from] serde_json::Error),
30    #[error(transparent)]
31    Path(#[from] PathError),
32}
33
34#[derive(Error, Debug)]
35pub enum StoreError {
36    #[error(transparent)]
37    Sqlite(#[from] rusqlite::Error),
38    #[error(transparent)]
39    Io(#[from] std::io::Error),
40    #[error(transparent)]
41    Json(#[from] serde_json::Error),
42}