wasmer_package/convert/
error.rs1use std::sync::Arc;
2
3#[derive(Clone, Debug)]
4pub struct ConversionError {
5 message: String,
6 cause: Option<Arc<dyn std::error::Error + Send + Sync>>,
7}
8
9impl ConversionError {
10 pub fn msg(msg: impl Into<String>) -> Self {
11 Self {
12 message: msg.into(),
13 cause: None,
14 }
15 }
16
17 pub fn with_cause(
18 msg: impl Into<String>,
19 cause: impl std::error::Error + Send + Sync + 'static,
20 ) -> Self {
21 Self {
22 message: msg.into(),
23 cause: Some(Arc::new(cause)),
24 }
25 }
26}
27
28impl std::fmt::Display for ConversionError {
29 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30 write!(f, "could not convert manifest: {}", self.message)?;
31 if let Some(cause) = &self.cause {
32 write!(f, " (cause: {cause})")?;
33 }
34
35 Ok(())
36 }
37}
38
39impl std::error::Error for ConversionError {
40 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
41 if let Some(e) = &self.cause {
42 Some(e)
43 } else {
44 None
45 }
46 }
47}