wavecraft_bridge/
error.rs1use thiserror::Error;
4use wavecraft_protocol::IpcError;
5
6#[derive(Debug, Error)]
8pub enum BridgeError {
9 #[error("Failed to parse JSON: {0}")]
11 JsonParse(#[from] serde_json::Error),
12
13 #[error("Parameter not found: {0}")]
15 ParameterNotFound(String),
16
17 #[error("Parameter value out of range: {id} = {value}")]
19 ParameterOutOfRange { id: String, value: f32 },
20
21 #[error("Unknown method: {0}")]
23 UnknownMethod(String),
24
25 #[error("Invalid params for method {method}: {reason}")]
27 InvalidParams { method: String, reason: String },
28
29 #[error("Internal bridge error: {0}")]
31 Internal(String),
32}
33
34impl BridgeError {
35 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}