1use std::path::PathBuf;
5
6#[derive(Debug)]
8#[non_exhaustive]
9pub enum Error {
10 NotARepository(PathBuf),
13 WorktreeNotFound(PathBuf),
15 Io(std::io::Error),
17 Vcs(processkit::Error),
19}
20
21impl std::fmt::Display for Error {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 match self {
24 Error::NotARepository(p) => {
25 write!(
26 f,
27 "no git or jj repository found at or above {}",
28 p.display()
29 )
30 }
31 Error::WorktreeNotFound(p) => {
32 write!(f, "no worktree found at {}", p.display())
33 }
34 Error::Io(e) => write!(f, "{e}"),
35 Error::Vcs(e) => write!(f, "{e}"),
36 }
37 }
38}
39
40impl std::error::Error for Error {
41 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
42 match self {
43 Error::Io(e) => Some(e),
44 Error::Vcs(e) => Some(e),
45 _ => None,
46 }
47 }
48}
49
50impl From<std::io::Error> for Error {
51 fn from(e: std::io::Error) -> Self {
52 Error::Io(e)
53 }
54}
55
56impl From<processkit::Error> for Error {
57 fn from(e: processkit::Error) -> Self {
58 Error::Vcs(e)
59 }
60}
61
62pub type Result<T> = std::result::Result<T, Error>;