loadsmith_install/error.rs
1use std::path::PathBuf;
2
3/// Errors that can occur during mod installation, extraction, or removal.
4///
5/// # Examples
6///
7/// ```rust
8/// use loadsmith_install::Error;
9///
10/// let err = Error::FileAlreadyExists("C:\\mods\\file.dll".into());
11/// assert!(err.to_string().contains("file already exists"));
12/// ```
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15 /// Wraps an [`std::io::Error`].
16 #[error(transparent)]
17 Io(#[from] std::io::Error),
18
19 /// Wraps a [`zip::result::ZipError`].
20 #[error(transparent)]
21 Zip(#[from] zip::result::ZipError),
22
23 /// Wraps a [`camino::FromPathBufError`] when a non-UTF-8 path is encountered.
24 #[error(transparent)]
25 InvalidUtf8(#[from] camino::FromPathBufError),
26
27 /// Wraps a [`walkdir::Error`] when walking directories.
28 #[error(transparent)]
29 Walkdir(#[from] walkdir::Error),
30
31 /// A file already exists at the target path and the conflict strategy is [`Error`](crate::ConflictStrategy::Error).
32 #[error("file already exists: {0}")]
33 FileAlreadyExists(PathBuf),
34
35 /// A path inside a zip archive could not be extracted (e.g. it escapes the archive root).
36 #[error("invalid zip path: {0}")]
37 InvalidZipPath(String),
38
39 /// A zip file index is out of bounds for the archive.
40 #[error("zip file index out of bounds: {index} (len={len})")]
41 ZipFileOutOfBounds { index: usize, len: usize },
42}
43
44/// Convenience alias for [`Error`] results.
45pub type Result<T> = std::result::Result<T, Error>;