1use std::{io, path::PathBuf};
2
3#[derive(thiserror::Error, Debug)]
5pub enum CoreError {
6 #[error("I/O error while accessing {0}")]
8 Io(PathBuf, #[source] io::Error),
9
10 #[error("invalid path: {0}")]
12 InvalidPath(String),
13
14 #[error("missing required value: {0}")]
16 MissingValue(String),
17
18 #[error("invalid command input: {0}")]
20 InvalidInput(String),
21
22 #[error("pre-condition failed: {0}")]
24 PreconditionFailed(String),
25
26 #[error("resource conflict: {0}")]
28 Conflict(String),
29
30 #[error("unsupported platform behavior: {0}")]
32 UnsupportedPlatform(String),
33}
34
35impl CoreError {
36 pub fn invalid_input(message: impl Into<String>) -> Self {
37 Self::InvalidInput(message.into())
38 }
39
40 pub fn missing(message: impl Into<String>) -> Self {
41 Self::MissingValue(message.into())
42 }
43
44 pub fn conflict(message: impl Into<String>) -> Self {
45 Self::Conflict(message.into())
46 }
47
48 pub fn io(path: impl Into<PathBuf>, error: io::Error) -> Self {
49 Self::Io(path.into(), error)
50 }
51}
52
53pub type Result<T> = std::result::Result<T, CoreError>;