use thiserror::Error;
#[derive(Debug, Error)]
pub enum BridgeError {
#[error("Failed to parse JSON: {0}")]
JsonParse(#[from] serde_json::Error),
#[error("Parameter not found: {0}")]
ParameterNotFound(String),
#[error("Parameter value out of range: {id} = {value}")]
ParameterOutOfRange { id: String, value: f32 },
#[error("Unknown method: {0}")]
UnknownMethod(String),
#[error("Invalid params for method {method}: {reason}")]
InvalidParams { method: String, reason: String },
#[error("Internal bridge error: {0}")]
Internal(String),
}
impl BridgeError {
pub fn to_ipc_error(&self) -> wavecraft_protocol::IpcError {
match self {
BridgeError::JsonParse(_) => wavecraft_protocol::IpcError::parse_error(),
BridgeError::ParameterNotFound(id) => wavecraft_protocol::IpcError::param_not_found(id),
BridgeError::ParameterOutOfRange { id, value } => {
wavecraft_protocol::IpcError::param_out_of_range(id, *value)
}
BridgeError::UnknownMethod(method) => {
wavecraft_protocol::IpcError::method_not_found(method)
}
BridgeError::InvalidParams { reason, .. } => {
wavecraft_protocol::IpcError::invalid_params(reason)
}
BridgeError::Internal(reason) => wavecraft_protocol::IpcError::internal_error(reason),
}
}
}