1use std::path::PathBuf;
2use thiserror::Error;
3
4use difflore_core::CoreError;
5
6#[derive(Error, Debug)]
7pub enum CliError {
8 #[error("{0}")]
9 Core(#[from] CoreError),
10
11 #[error("{0}")]
12 Io(#[from] std::io::Error),
13
14 #[error("{0}")]
15 Json(#[from] serde_json::Error),
16
17 #[error("{0}")]
18 Sqlx(#[from] sqlx::Error),
19
20 #[error("{0}")]
21 Message(String),
22
23 #[error("config at {path}: {message}")]
24 Config { path: PathBuf, message: String },
25}
26
27impl CliError {
28 pub fn msg<S: Into<String>>(s: S) -> Self {
29 Self::Message(s.into())
30 }
31}
32
33impl From<String> for CliError {
34 fn from(s: String) -> Self {
35 Self::Message(s)
36 }
37}
38
39impl From<&str> for CliError {
40 fn from(s: &str) -> Self {
41 Self::Message(s.to_owned())
42 }
43}
44
45pub type CliResult<T> = Result<T, CliError>;