Skip to main content

wavecraft_bridge/
error.rs

1//! Error types for the IPC bridge layer
2
3use thiserror::Error;
4use wavecraft_protocol::IpcError;
5
6/// Bridge-specific errors that occur during IPC handling
7#[derive(Debug, Error)]
8pub enum BridgeError {
9    /// JSON parsing failed
10    #[error("Failed to parse JSON: {0}")]
11    JsonParse(#[from] serde_json::Error),
12
13    /// Parameter not found in host
14    #[error("Parameter not found: {0}")]
15    ParameterNotFound(String),
16
17    /// Parameter value out of valid range
18    #[error("Parameter value out of range: {id} = {value}")]
19    ParameterOutOfRange { id: String, value: f32 },
20
21    /// Method not supported by handler
22    #[error("Unknown method: {0}")]
23    UnknownMethod(String),
24
25    /// Invalid parameters for method
26    #[error("Invalid params for method {method}: {reason}")]
27    InvalidParams { method: String, reason: String },
28
29    /// Internal error in bridge logic
30    #[error("Internal bridge error: {0}")]
31    Internal(String),
32}
33
34impl BridgeError {
35    /// Convert BridgeError to IpcError from protocol
36    pub fn to_ipc_error(&self) -> IpcError {
37        match self {
38            Self::JsonParse(_) => IpcError::parse_error(),
39            Self::ParameterNotFound(id) => IpcError::param_not_found(id),
40            Self::ParameterOutOfRange { id, value } => IpcError::param_out_of_range(id, *value),
41            Self::UnknownMethod(method) => IpcError::method_not_found(method),
42            Self::InvalidParams { reason, .. } => IpcError::invalid_params(reason),
43            Self::Internal(reason) => IpcError::internal_error(reason),
44        }
45    }
46}