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 Doctor(String),
40 SchemaQualityEmpty {
42 component: String,
43 operation: String,
44 direction: &'static str,
45 suggestion: String,
46 },
47}
48
49impl ComponentError {
50 pub fn code(&self) -> &'static str {
51 match self {
52 ComponentError::Manifest(_) => "manifest-invalid",
53 ComponentError::SchemaIntrospection(_) => "schema-introspection",
54 #[cfg(feature = "abi")]
55 ComponentError::Abi(err) => match err {
56 crate::abi::AbiError::WorldMismatch { .. } => "world-mismatch",
57 crate::abi::AbiError::MissingWasiTarget => "wasi-target-missing",
58 _ => "abi-error",
59 },
60 #[cfg(feature = "describe")]
61 ComponentError::Describe(err) => match err {
62 crate::describe::DescribeError::NotFound(_) => "describe-missing",
63 crate::describe::DescribeError::Json { .. } => "describe-invalid",
64 crate::describe::DescribeError::Io { .. } => "describe-io",
65 crate::describe::DescribeError::Metadata(_) => "describe-metadata",
66 },
67 #[cfg(feature = "loader")]
68 ComponentError::Load(_) => "component-load",
69 ComponentError::Capability(_) => "capability-error",
70 ComponentError::Limits(_) => "limits-error",
71 ComponentError::Signing(_) => "hash-mismatch",
72 ComponentError::Io(_) => "io-error",
73 ComponentError::Doctor(_) => "doctor-failure",
74 ComponentError::SchemaQualityEmpty { .. } => "E_OP_SCHEMA_EMPTY",
75 }
76 }
77}