1use webc::{ContainerError, DetectError};
2
3#[cfg(feature = "authoring")]
4pub use self::authoring::AuthoringError;
5
6#[derive(Debug, thiserror::Error)]
8#[allow(clippy::result_large_err)]
9#[non_exhaustive]
10pub enum WasmerPackageError {
11 #[cfg(feature = "authoring")]
13 #[error(transparent)]
14 Authoring(#[from] AuthoringError),
15
16 #[error("container error: {0:?}")]
18 ContainerError(#[from] ContainerError),
19
20 #[error("detect error: {0:?}")]
22 DetectError(#[from] DetectError),
23}
24
25#[cfg(feature = "authoring")]
26mod authoring {
27 use std::path::PathBuf;
28
29 use crate::package::ManifestError;
30
31 use super::WasmerPackageError;
32
33 #[derive(Debug, thiserror::Error)]
36 #[non_exhaustive]
37 pub enum AuthoringError {
38 #[error("Unable to create a temporary directory")]
40 TempDir(#[source] std::io::Error),
41 #[error("Unable to open \"{}\"", path.display())]
43 FileOpen {
44 path: PathBuf,
46 #[source]
48 error: std::io::Error,
49 },
50 #[error("Unable to read \"{}\"", path.display())]
52 FileRead {
53 path: PathBuf,
55 #[source]
57 error: std::io::Error,
58 },
59
60 #[error("IO Error: {0:?}")]
62 IoError(#[from] std::io::Error),
63
64 #[error("Malformed path format: {0:?}")]
66 MalformedPath(PathBuf),
67
68 #[error("Unable to extract the tarball")]
70 Tarball(#[source] std::io::Error),
71 #[error("Unable to deserialize \"{}\"", path.display())]
73 TomlDeserialize {
74 path: PathBuf,
76 #[source]
78 error: toml::de::Error,
79 },
80 #[error("Unable to deserialize \"{}\"", path.display())]
82 JsonDeserialize {
83 path: PathBuf,
85 #[source]
87 error: serde_json::Error,
88 },
89 #[error("Unable to find the \"wasmer.toml\"")]
91 MissingManifest,
92 #[error("Unable to get the absolute path for \"{}\"", path.display())]
94 Canonicalize {
95 path: PathBuf,
97 #[source]
99 error: std::io::Error,
100 },
101 #[error("Unable to load the \"wasmer.toml\" manifest")]
103 Manifest(#[from] ManifestError),
104 #[error("The manifest is invalid")]
106 Validation(#[from] wasmer_config::package::ValidationError),
107 #[error("Path: \"{}\" does not exist", path.display())]
109 PathNotExists {
110 path: PathBuf,
112 },
113 #[error("Volume creation failed: {0:?}")]
115 VolumeCreation(#[from] anyhow::Error),
116
117 #[error("serde error: {0:?}")]
119 SerdeError(#[from] ciborium::value::Error),
120 }
121
122 macro_rules! forward_from {
125 ($($source:ty),* $(,)?) => {
126 $(
127 impl From<$source> for WasmerPackageError {
128 fn from(error: $source) -> Self {
129 WasmerPackageError::Authoring(error.into())
130 }
131 }
132 )*
133 };
134 }
135
136 forward_from!(
137 std::io::Error,
138 ManifestError,
139 wasmer_config::package::ValidationError,
140 anyhow::Error,
141 ciborium::value::Error,
142 );
143}