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}: `spec/` is not empty")]
29 NotEmpty(PathBuf),
30 #[error("{0}: `spec/` already exists")]
31 Exists(PathBuf),
32 #[error("{0}: a save is already in progress")]
33 Pending(PathBuf),
34 #[error("{0}: {1}")]
35 Journal(PathBuf, String),
36 #[error("{0}: not inside a git repository; a publish needs one")]
37 NotARepository(PathBuf),
38 #[error("git could not run `{0} --version` from the top of the working tree")]
40 Launcher(String),
41 #[error("git cannot be run: {0}")]
42 GitUnavailable(String),
43 #[error("`git {call}` failed: {message}")]
44 Git { call: String, message: String },
45 #[error("SOURCE_DATE_EPOCH is {0:?}, not a whole number of seconds")]
46 Epoch(String),
47 #[error("{0}: not a valid lock record: {1}")]
48 Lock(PathBuf, LockError),
49}
50
51pub(crate) fn io_error(path: &Path) -> impl FnOnce(io::Error) -> StoreError + '_ {
52 move |source| StoreError::Io {
53 path: path.to_path_buf(),
54 source,
55 }
56}