use std::ffi::OsString;
use std::path::PathBuf;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, self::Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("The 'POSTIT_ROOT' environment variable is empty")]
EmptyEnvVar,
#[error("The value of 'POSTIT_ROOT' is not a valid path or is a relative path: {0}")]
InvalidPathEnvVar(PathBuf),
#[error("The value of 'POSTIT_ROOT' is not unicode: {0:?}")]
NotUnicode(OsString),
#[error("The configuration file doesn't exist at '{0}'")]
FileDoesntExist(PathBuf),
#[error("The configuration file already exists at '{0}'")]
FileAlreadyExists(PathBuf),
#[error("You must provide arguments to set (e.g.: --persister tasks.json)")]
EmptySetArgs,
#[error("{0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
Env(#[from] std::env::VarError),
#[error("Failed to serialize config to TOML: {0}")]
TOMLSerialize(#[from] toml::ser::Error),
#[error("Failed to deserialize TOML to config: {0}")]
TOMLDeserialize(#[from] toml::de::Error),
#[error("{0}")]
Other(#[from] Box<dyn std::error::Error + Send + Sync>),
}
impl Error {
#[inline]
pub fn wrap<E>(err: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::Other(err.into())
}
}