pub_just/
search_error.rs

1use super::*;
2
3#[derive(Debug, Snafu)]
4#[snafu(visibility(pub))]
5pub enum SearchError {
6  #[snafu(display("Cannot initialize global justfile"))]
7  GlobalJustfileInit,
8  #[snafu(display("Global justfile not found"))]
9  GlobalJustfileNotFound,
10  #[snafu(display(
11    "I/O error reading directory `{}`: {}",
12    directory.display(),
13    io_error
14  ))]
15  Io {
16    directory: PathBuf,
17    io_error: io::Error,
18  },
19  #[snafu(display("Justfile path had no parent: {}", path.display()))]
20  JustfileHadNoParent { path: PathBuf },
21  #[snafu(display(
22    "Multiple candidate justfiles found in `{}`: {}",
23    candidates.iter().next().unwrap().parent().unwrap().display(),
24    List::and_ticked(
25      candidates
26        .iter()
27        .map(|candidate| candidate.file_name().unwrap().to_string_lossy())
28    ),
29  ))]
30  MultipleCandidates { candidates: BTreeSet<PathBuf> },
31  #[snafu(display("No justfile found"))]
32  NotFound,
33}
34
35#[cfg(test)]
36mod tests {
37  use super::*;
38
39  #[test]
40  fn multiple_candidates_formatting() {
41    let error = SearchError::MultipleCandidates {
42      candidates: [Path::new("/foo/justfile"), Path::new("/foo/JUSTFILE")]
43        .iter()
44        .map(|path| path.to_path_buf())
45        .collect(),
46    };
47
48    assert_eq!(
49      error.to_string(),
50      "Multiple candidate justfiles found in `/foo`: `JUSTFILE` and `justfile`"
51    );
52  }
53}