فهرست منبع

error: enhance RpcError to support custom server errors and method not found

This update extends the `RpcError` enum to include support for two new variants: `ServerError` and `MethodNotFound`.

### Details:
- `ServerError` utilizes a `dyn std::error::Error` trait object, providing flexibility to embed and propagate custom errors defined by RPC-related modules.
- `ServerError` is wrapped in an `Arc`, which automatically implements the `Send` and `Sync` traits. This ensures `RpcError` can be safely shared and propagated across thread boundaries during asynchronous operations, like the `StoppableTask` and other multi-threaded components.
kalm 1 سال پیش
والد
کامیت
9ce37ee843
1فایلهای تغییر یافته به همراه6 افزوده شده و 0 حذف شده
  1. 6 0
      src/error.rs

+ 6 - 0
src/error.rs

@@ -638,6 +638,12 @@ pub enum RpcError {
 
     #[error("IO Error: {0}")]
     IoError(std::io::ErrorKind),
+
+    #[error("Method not found: {0}")]
+    MethodNotFound(String),
+
+    #[error("Server-side Error: {0}")]
+    ServerError(#[from] std::sync::Arc<dyn std::error::Error + Send + Sync + 'static>),
 }
 
 #[cfg(feature = "rpc")]