greentic_component/
error.rs1use displaydoc::Display;
2
3#[cfg(feature = "abi")]
4use crate::abi::AbiError;
5use crate::capabilities::CapabilityError;
6#[cfg(feature = "describe")]
7use crate::describe::DescribeError;
8use crate::limits::LimitError;
9#[cfg(feature = "loader")]
10use crate::loader::LoadError;
11use crate::manifest::ManifestError;
12use crate::schema::SchemaIntrospectionError;
13use crate::signing::SigningError;
14
15#[derive(Debug, Display, thiserror::Error)]
16pub enum ComponentError {
17 Manifest(#[from] ManifestError),
19 SchemaIntrospection(#[from] SchemaIntrospectionError),
21 #[cfg(feature = "abi")]
23 Abi(#[from] AbiError),
24 #[cfg(feature = "describe")]
26 Describe(#[from] DescribeError),
27 #[cfg(feature = "loader")]
29 Load(#[from] LoadError),
30 Capability(#[from] CapabilityError),
32 Limits(#[from] LimitError),
34 Signing(#[from] SigningError),
36 Io(#[from] std::io::Error),
38}
39
40impl ComponentError {
41 pub fn code(&self) -> &'static str {
42 match self {
43 ComponentError::Manifest(_) => "manifest-invalid",
44 ComponentError::SchemaIntrospection(_) => "schema-introspection",
45 #[cfg(feature = "abi")]
46 ComponentError::Abi(err) => match err {
47 crate::abi::AbiError::WorldMismatch { .. } => "world-mismatch",
48 crate::abi::AbiError::MissingWasiTarget => "wasi-target-missing",
49 _ => "abi-error",
50 },
51 #[cfg(feature = "describe")]
52 ComponentError::Describe(err) => match err {
53 crate::describe::DescribeError::NotFound(_) => "describe-missing",
54 crate::describe::DescribeError::Json { .. } => "describe-invalid",
55 crate::describe::DescribeError::Io { .. } => "describe-io",
56 crate::describe::DescribeError::Metadata(_) => "describe-metadata",
57 },
58 #[cfg(feature = "loader")]
59 ComponentError::Load(_) => "component-load",
60 ComponentError::Capability(_) => "capability-error",
61 ComponentError::Limits(_) => "limits-error",
62 ComponentError::Signing(_) => "hash-mismatch",
63 ComponentError::Io(_) => "io-error",
64 }
65 }
66}