starbase_archive/
archive_error.rs1use starbase_styles::{Style, Stylize};
2use starbase_utils::fs::FsError;
3use starbase_utils::glob::GlobError;
4use std::path::PathBuf;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8#[cfg_attr(feature = "miette", derive(miette::Diagnostic))]
9pub enum ArchiveError {
10 #[error(transparent)]
11 Fs(#[from] Box<FsError>),
12
13 #[error(transparent)]
14 Glob(#[from] Box<GlobError>),
15
16 #[cfg(feature = "gz")]
17 #[error(transparent)]
18 Gz(#[from] Box<crate::gz::GzError>),
19
20 #[error(transparent)]
21 Io(#[from] Box<std::io::Error>),
22
23 #[cfg(feature = "tar")]
24 #[error(transparent)]
25 Tar(#[from] Box<crate::tar::TarError>),
26
27 #[cfg(feature = "zip")]
28 #[error(transparent)]
29 Zip(#[from] Box<crate::zip::ZipError>),
30
31 #[cfg_attr(feature = "miette", diagnostic(code(archive::feature_required)))]
32 #[error(
33 "Unable to handle archive {}. This format requires the {} feature to be enabled.",
34 .path.style(Style::Path),
35 .feature.style(Style::Symbol),
36 )]
37 FeatureNotEnabled { feature: String, path: PathBuf },
38
39 #[cfg_attr(feature = "miette", diagnostic(code(archive::unsupported_format)))]
40 #[error(
41 "Unable to handle archive {}, unsupported format {}.",
42 .path.style(Style::Path),
43 .format.style(Style::Symbol),
44 )]
45 UnsupportedFormat { format: String, path: PathBuf },
46
47 #[cfg_attr(feature = "miette", diagnostic(code(archive::unknown_format)))]
48 #[error(
49 "Unable to handle archive {}, could not determine format.",
50 .path.style(Style::Path),
51 )]
52 UnknownFormat { path: PathBuf },
53}
54
55impl From<FsError> for ArchiveError {
56 fn from(e: FsError) -> ArchiveError {
57 ArchiveError::Fs(Box::new(e))
58 }
59}
60
61impl From<GlobError> for ArchiveError {
62 fn from(e: GlobError) -> ArchiveError {
63 ArchiveError::Glob(Box::new(e))
64 }
65}
66
67#[cfg(feature = "gz")]
68impl From<crate::gz::GzError> for ArchiveError {
69 fn from(e: crate::gz::GzError) -> ArchiveError {
70 ArchiveError::Gz(Box::new(e))
71 }
72}
73
74#[cfg(feature = "tar")]
75impl From<crate::tar::TarError> for ArchiveError {
76 fn from(e: crate::tar::TarError) -> ArchiveError {
77 ArchiveError::Tar(Box::new(e))
78 }
79}
80
81#[cfg(feature = "zip")]
82impl From<crate::zip::ZipError> for ArchiveError {
83 fn from(e: crate::zip::ZipError) -> ArchiveError {
84 ArchiveError::Zip(Box::new(e))
85 }
86}