1use std::path::PathBuf;
2
3#[derive(Clone, Debug)]
5pub enum ProjectRemedy {
6 Choose(Vec<PathBuf>),
8 Rename {
10 source: PathBuf,
12 name: String,
14 },
15}
16
17#[derive(Clone, Debug)]
19pub struct WorktreeLocations {
20 pub registered: PathBuf,
22 pub candidate: PathBuf,
24}
25
26#[derive(Clone, Debug)]
28pub enum ProblemDetail {
29 GitDiagnostic(String),
31 StartingPoint(String),
33 MissingWorktree {
35 participant: String,
37 expected: PathBuf,
39 occupied: bool,
41 },
42 TaskDirectoryConflict {
44 workspace: PathBuf,
46 current: PathBuf,
48 },
49}
50
51#[derive(Clone, Debug)]
53pub struct Problem {
54 pub worktree_locations: Option<Box<WorktreeLocations>>,
56 pub code: crate::ProblemCode,
58 pub message: String,
60 pub remedy: String,
62 pub project_remedy: Option<Box<ProjectRemedy>>,
64 pub repositories: Vec<PathBuf>,
66 pub detail: Option<Box<ProblemDetail>>,
68}
69
70impl Problem {
71 pub fn new(code: crate::ProblemCode, message: impl Into<String>) -> Self {
73 Self {
74 code,
75 message: message.into(),
76 remedy: String::new(),
77 project_remedy: None,
78 worktree_locations: None,
79 repositories: Vec::new(),
80 detail: None,
81 }
82 }
83
84 pub fn remedy(mut self, remedy: impl Into<String>) -> Self {
86 self.remedy = remedy.into();
87 self
88 }
89
90 pub fn in_repository(mut self, path: &std::path::Path) -> Self {
92 self.repositories.push(path.into());
93 self
94 }
95
96 pub(crate) fn unconfirmed_git_exit(context: impl std::fmt::Display) -> Self {
98 let message = format!("Workyard cannot confirm Git finished {context}.");
99 let remedy = "You can inspect files. Leave the worktree in place while checking Git and its hooks. \
100 If the original Workyard process has exited, retrying cannot clear this interruption.";
101
102 Self::new(crate::ProblemCode::ResourceBusy, message).remedy(remedy)
103 }
104
105 pub fn io(context: impl std::fmt::Display, error: std::io::Error) -> Self {
107 Self::new(crate::ProblemCode::IoError, format!("{context}: {error}"))
108 }
109}
110
111impl std::fmt::Display for Problem {
112 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113 write!(f, "{}: {}", self.code, self.message)
114 }
115}
116impl std::error::Error for Problem {}