1use std::path::{Path, PathBuf};
2use thiserror::Error;
3
4#[derive(Debug, Error, PartialEq, Eq)]
6pub enum ConcurrentCollectionError {
7 #[error("lock is poisoned")]
8 Poison,
9}
10
11#[derive(Debug, Error, PartialEq, Eq)]
13pub enum ParseError {
14 #[error("parse error: invalid number: {0}")]
15 InvalidNumber(String),
16}
17
18#[derive(Debug, Error, PartialEq, Eq)]
20pub enum FsError {
21 #[error("path does not exist: {0}")]
22 PathDoesNotExist(PathBuf),
23
24 #[error("path is not a directory: {0}")]
25 PathIsNotDirectory(PathBuf),
26
27 #[error("failed to read directory entry")]
28 DirEntry,
29
30 #[error("failed to read directory: {0}")]
31 DirRead(PathBuf),
32
33 #[error("failed to get file type for `{0}`")]
34 FileType(PathBuf),
35
36 #[error("skipping non-file/non-directory entry: {0}")]
37 NonFileNonDir(PathBuf),
38}
39
40impl FsError {
41 pub fn path_does_not_exist<P>(path: P) -> Self
43 where
44 P: AsRef<Path>,
45 {
46 Self::PathDoesNotExist(path.as_ref().to_path_buf())
47 }
48
49 pub fn path_is_not_directory<P>(path: P) -> Self
51 where
52 P: AsRef<Path>,
53 {
54 Self::PathIsNotDirectory(path.as_ref().to_path_buf())
55 }
56
57 pub fn dir_read<P>(path: P) -> Self
59 where
60 P: AsRef<Path>,
61 {
62 Self::DirRead(path.as_ref().to_path_buf())
63 }
64
65 pub fn file_type<P>(path: P) -> Self
67 where
68 P: AsRef<Path>,
69 {
70 Self::FileType(path.as_ref().to_path_buf())
71 }
72
73 pub fn non_file_non_dir<P>(path: P) -> Self
75 where
76 P: AsRef<Path>,
77 {
78 Self::NonFileNonDir(path.as_ref().to_path_buf())
79 }
80}