From e822fad74e403fbcf3d615cb882a80416de75e1c Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 4 Sep 2024 17:20:59 +0200 Subject: [PATCH] chore: renamed and fixed errors Co-authored-by: zaaarf --- src/client.rs | 13 +++++++------ src/errors.rs | 38 +++++++------------------------------- src/workspace/worker.rs | 12 ++++++------ 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/src/client.rs b/src/client.rs index 144db4d..762a7a2 100644 --- a/src/client.rs +++ b/src/client.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use dashmap::DashMap; use tonic::{service::interceptor::InterceptedService, transport::{Channel, Endpoint}}; -use crate::{api::User, errors::{ConnectionResult, ProcedureResult}, ext::InternallyMutable, workspace::Workspace}; +use crate::{api::User, errors::{ConnectionResult, RemoteResult}, ext::InternallyMutable, workspace::Workspace}; use codemp_proto::{ auth::{auth_client::AuthClient, LoginRequest}, common::{Empty, Token}, session::{session_client::SessionClient, InviteRequest, WorkspaceRequest}, @@ -75,7 +75,7 @@ impl Client { } /// refresh session token - pub async fn refresh(&self) -> ProcedureResult<()> { + pub async fn refresh(&self) -> tonic::Result<()> { let new_token = self.0.auth.clone().refresh(self.0.claims.get()) .await? .into_inner(); @@ -84,7 +84,7 @@ impl Client { } /// attempts to create a new workspace with given name - pub async fn create_workspace(&self, name: impl AsRef) -> ProcedureResult<()> { + pub async fn create_workspace(&self, name: impl AsRef) -> RemoteResult<()> { self.0.session .clone() .create_workspace(WorkspaceRequest { workspace: name.as_ref().to_string() }) @@ -93,7 +93,7 @@ impl Client { } /// delete an existing workspace if possible - pub async fn delete_workspace(&self, name: impl AsRef) -> ProcedureResult<()> { + pub async fn delete_workspace(&self, name: impl AsRef) -> RemoteResult<()> { self.0.session .clone() .delete_workspace(WorkspaceRequest { workspace: name.as_ref().to_string() }) @@ -102,7 +102,7 @@ impl Client { } /// invite user associated with username to workspace, if possible - pub async fn invite_to_workspace(&self, workspace_name: impl AsRef, user_name: impl AsRef) -> ProcedureResult<()> { + pub async fn invite_to_workspace(&self, workspace_name: impl AsRef, user_name: impl AsRef) -> RemoteResult<()> { self.0.session .clone() .invite_to_workspace(InviteRequest { @@ -114,7 +114,7 @@ impl Client { } /// list all available workspaces, filtering between those owned and those invited to - pub async fn list_workspaces(&self, owned: bool, invited: bool) -> ProcedureResult> { + pub async fn list_workspaces(&self, owned: bool, invited: bool) -> RemoteResult> { let mut workspaces = self.0.session .clone() .list_workspaces(Empty {}) @@ -131,6 +131,7 @@ impl Client { /// join a workspace, returns [Workspace] pub async fn join_workspace(&self, workspace: impl AsRef) -> ConnectionResult { + // STATUS let token = self.0.session .clone() .access_workspace(WorkspaceRequest { workspace: workspace.as_ref().to_string() }) diff --git a/src/errors.rs b/src/errors.rs index da3a6b9..5e5b11c 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,30 +1,8 @@ - -#[deprecated = "use underlying errors to provide more context on what errors could really be thrown"] -#[allow(deprecated)] -pub type Result = std::result::Result; - -#[deprecated = "use underlying errors to provide more context on what errors could really be thrown"] -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[error("connection error: {0}")] - Connection(#[from] ConnectionError), - - #[error("procedure error: {0}")] - Procedure(#[from] ProcedureError), - - #[error("controller error: {0}")] - Controller(#[from] ControllerError), -} - - - -pub type ProcedureResult = std::result::Result; +pub type RemoteResult = std::result::Result; #[derive(Debug, thiserror::Error)] -pub enum ProcedureError { - #[error("server rejected procedure with error: {0}")] - Server(#[from] tonic::Status) -} +#[error("server rejected procedure with error code: {0}")] +pub struct RemoteError(#[from] tonic::Status); @@ -36,14 +14,12 @@ pub enum ConnectionError { Transport(#[from] tonic::transport::Error), #[error("server rejected connection attempt: {0}")] - Procedure(#[from] tonic::Status), + Remote(#[from] RemoteError), } -impl From for ConnectionError { - fn from(value: ProcedureError) -> Self { - match value { - ProcedureError::Server(x) => Self::Procedure(x) - } +impl From for ConnectionError { + fn from(value: tonic::Status) -> Self { + Self::Remote(RemoteError(value)) } } diff --git a/src/workspace/worker.rs b/src/workspace/worker.rs index dd32877..8906100 100644 --- a/src/workspace/worker.rs +++ b/src/workspace/worker.rs @@ -2,7 +2,7 @@ use crate::{ api::{controller::ControllerWorker, Controller, Event, User}, buffer::{self, worker::BufferWorker}, cursor::{self, worker::CursorWorker}, - errors::{ConnectionResult, ControllerResult, ProcedureResult}, + errors::{ConnectionResult, ControllerResult, RemoteResult}, ext::InternallyMutable, workspace::service::Services }; @@ -146,7 +146,7 @@ impl Workspace { impl Workspace { /// create a new buffer in current workspace - pub async fn create(&self, path: &str) -> ProcedureResult<()> { + pub async fn create(&self, path: &str) -> RemoteResult<()> { let mut workspace_client = self.0.services.ws(); workspace_client .create_buffer(tonic::Request::new(BufferNode { @@ -233,7 +233,7 @@ impl Workspace { } /// fetch a list of all buffers in a workspace - pub async fn fetch_buffers(&self) -> ProcedureResult<()> { + pub async fn fetch_buffers(&self) -> RemoteResult<()> { let mut workspace_client = self.0.services.ws(); let buffers = workspace_client .list_buffers(tonic::Request::new(Empty {})) @@ -250,7 +250,7 @@ impl Workspace { } /// fetch a list of all users in a workspace - pub async fn fetch_users(&self) -> ProcedureResult<()> { + pub async fn fetch_users(&self) -> RemoteResult<()> { let mut workspace_client = self.0.services.ws(); let users = BTreeSet::from_iter( workspace_client @@ -273,7 +273,7 @@ impl Workspace { /// get a list of the users attached to a specific buffer /// /// TODO: discuss implementation details - pub async fn list_buffer_users(&self, path: &str) -> ProcedureResult> { + pub async fn list_buffer_users(&self, path: &str) -> RemoteResult> { let mut workspace_client = self.0.services.ws(); let buffer_users = workspace_client .list_buffer_users(tonic::Request::new(BufferNode { @@ -290,7 +290,7 @@ impl Workspace { } /// delete a buffer - pub async fn delete(&self, path: &str) -> ProcedureResult<()> { + pub async fn delete(&self, path: &str) -> RemoteResult<()> { let mut workspace_client = self.0.services.ws(); workspace_client .delete_buffer(tonic::Request::new(BufferNode {