1use std::io;
4use std::path::{Path, PathBuf};
5
6use loftspec::codec::ReadError;
7use loftspec::index::IndexErrors;
8use loftspec::publish::LockError;
9
10#[derive(Debug, thiserror::Error)]
11pub enum StoreError {
12 #[error("the store holds no document")]
13 NoDocument,
14 #[error("{}", .0.iter().map(ToString::to_string).collect::<Vec<_>>().join("\n"))]
15 Read(Vec<ReadError>),
16 #[error("the document does not index: {0:?}")]
17 Index(IndexErrors),
18 #[error("{0}: there is no `spec/` directory")]
19 NoTree(PathBuf),
20 #[error("{path}: {source}")]
21 Io {
22 path: PathBuf,
23 #[source]
24 source: io::Error,
25 },
26 #[error("{0}: a file name that is not UTF-8")]
27 NotUtf8(PathBuf),
28 #[error("{0}: the bytes are not UTF-8")]
29 NotText(PathBuf),
30 #[error("{0}: `spec/` is not empty")]
31 NotEmpty(PathBuf),
32 #[error("{0}: `spec/` already exists")]
33 Exists(PathBuf),
34 #[error("{0}: a save is already in progress")]
35 Pending(PathBuf),
36 #[error("{0}: {1}")]
37 Journal(PathBuf, String),
38 #[error("{0}: not inside a git repository; a publish needs one")]
39 NotARepository(PathBuf),
40 #[error("git could not run `{0} --version` from the top of the working tree")]
42 Launcher(String),
43 #[error("git cannot be run: {0}")]
44 GitUnavailable(String),
45 #[error("`git {call}` failed: {message}")]
46 Git { call: String, message: String },
47 #[error("SOURCE_DATE_EPOCH is {0:?}, not a whole number of seconds")]
48 Epoch(String),
49 #[error("{0}: not a valid lock record: {1}")]
50 Lock(PathBuf, LockError),
51}
52
53pub(crate) fn io_error(path: &Path) -> impl FnOnce(io::Error) -> StoreError + '_ {
54 move |source| StoreError::Io {
55 path: path.to_path_buf(),
56 source,
57 }
58}