shared_target_core/
error.rs1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5 #[error("no target directory at {0}")]
6 SourceMissing(PathBuf),
7
8 #[error("{0} already exists")]
9 DestinationExists(PathBuf),
10
11 #[error("a previous run left a partial tree at {0}; remove it and run again")]
12 StagingExists(PathBuf),
13
14 #[error("a build is running here: {path} is locked; seed between builds")]
18 SourceBusy { path: PathBuf },
19
20 #[error("{0} has no parent directory to be created in")]
21 DestinationHasNoParent(PathBuf),
22
23 #[error("{dest} is inside {src}, which is the directory being read")]
26 DestinationInsideSource { src: PathBuf, dest: PathBuf },
27
28 #[error(
32 "{src} and {dest} are on different filesystems, so there is nothing to share between them"
33 )]
34 CrossDevice { src: PathBuf, dest: PathBuf },
35
36 #[error("{op} {path}")]
37 Io {
38 op: &'static str,
39 path: PathBuf,
40 #[source]
41 source: std::io::Error,
42 },
43
44 #[error("walking {path}")]
45 Walk {
46 path: PathBuf,
47 #[source]
48 source: walkdir::Error,
49 },
50
51 #[error("running `cargo metadata`")]
52 MetadataSpawn(#[source] std::io::Error),
53
54 #[error("`cargo metadata` failed: {0}")]
55 MetadataFailed(String),
56
57 #[error("reading the output of `cargo metadata`")]
58 MetadataParse(#[source] serde_json::Error),
59
60 #[error("`cargo metadata` reported no target directory")]
61 MetadataNoTargetDir,
62}
63
64pub type Result<T> = std::result::Result<T, Error>;
65
66impl Error {
67 pub(crate) fn io(
70 op: &'static str,
71 path: impl Into<PathBuf>,
72 ) -> impl FnOnce(std::io::Error) -> Error {
73 let path = path.into();
74 move |source| Error::Io { op, path, source }
75 }
76}