|
| 1 | +use std::fmt::Debug; |
| 2 | +use thiserror::Error; |
| 3 | + |
| 4 | +use crate::ModuleInstanceId; |
| 5 | + |
| 6 | +/// Various errors that may be encountered when invoking runtime code. |
| 7 | +#[derive(Error, Debug)] |
| 8 | +pub enum CommonRuntimeError { |
| 9 | + /// A Wasm Component failed to prepare |
| 10 | + #[error("Failed to prepare a Wasm Component: {0}")] |
| 11 | + PreparationFailed(String), |
| 12 | + |
| 13 | + /// A Wasm Component failed to link |
| 14 | + #[error("Failed to link a Wasm Component: {0}")] |
| 15 | + LinkFailed(String), |
| 16 | + |
| 17 | + /// A sandbox failed to be created |
| 18 | + #[error("Failed to instantiate a sandbox: {0}")] |
| 19 | + SandboxCreationFailed(String), |
| 20 | + |
| 21 | + /// A Common Module failed to be instantiated |
| 22 | + #[error("Failed to instantiate a Common Module: {0}")] |
| 23 | + ModuleInstantiationFailed(String), |
| 24 | + |
| 25 | + /// An error occurred when a Common Module was run |
| 26 | + #[error("Failed to run a Common Module: {0}")] |
| 27 | + ModuleRunFailed(String), |
| 28 | + |
| 29 | + /// An unexpected internal error occurred |
| 30 | + #[error("Internal error")] |
| 31 | + InternalError(String), |
| 32 | + |
| 33 | + /// A specified Common Module ID was not valid |
| 34 | + #[error("Invalid Common Module ID: {0}")] |
| 35 | + InvalidModuleId(String), |
| 36 | + |
| 37 | + /// The configured target was missing or invalid |
| 38 | + #[error("Invalid Common Module Target: {0}")] |
| 39 | + InvalidModuleTarget(String), |
| 40 | + |
| 41 | + /// The configured target was missing or invalid |
| 42 | + #[error("Invalid Common Module Affinity: {0}")] |
| 43 | + InvalidModuleAffinity(String), |
| 44 | + |
| 45 | + /// The specified Common Module instance ID did not correspond to a living |
| 46 | + /// instance |
| 47 | + #[error("Unknown Common Module instance ID: {0}")] |
| 48 | + UnknownInstanceId(ModuleInstanceId), |
| 49 | + |
| 50 | + /// A provided Value was empty or of an unexpected shape |
| 51 | + #[error("Invalid Value")] |
| 52 | + InvalidValue, |
| 53 | + |
| 54 | + /// The provided module sources were missing or otherwise invalid |
| 55 | + #[error("Invalid module source: {0}")] |
| 56 | + InvalidModuleSource(String), |
| 57 | + |
| 58 | + /// The provided instantiation parameters are not supported |
| 59 | + #[error("Invalid instantiation parameters: {0}")] |
| 60 | + InvalidInstantiationParameters(String), |
| 61 | +} |
| 62 | + |
| 63 | +#[cfg(not(target_arch = "wasm32"))] |
| 64 | +impl From<tonic::transport::Error> for CommonRuntimeError { |
| 65 | + fn from(value: tonic::transport::Error) -> Self { |
| 66 | + CommonRuntimeError::InternalError(format!("{value}")) |
| 67 | + } |
| 68 | +} |
0 commit comments