chore: renamed and fixed errors

Co-authored-by: zaaarf <me@zaaarf.foo>
This commit is contained in:
əlemi 2024-09-04 17:20:59 +02:00 committed by zaaarf
parent c879d93452
commit e822fad74e
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
3 changed files with 20 additions and 43 deletions

View file

@ -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<str>) -> ProcedureResult<()> {
pub async fn create_workspace(&self, name: impl AsRef<str>) -> 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<str>) -> ProcedureResult<()> {
pub async fn delete_workspace(&self, name: impl AsRef<str>) -> 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<str>, user_name: impl AsRef<str>) -> ProcedureResult<()> {
pub async fn invite_to_workspace(&self, workspace_name: impl AsRef<str>, user_name: impl AsRef<str>) -> 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<Vec<String>> {
pub async fn list_workspaces(&self, owned: bool, invited: bool) -> RemoteResult<Vec<String>> {
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<str>) -> ConnectionResult<Workspace> {
// STATUS
let token = self.0.session
.clone()
.access_workspace(WorkspaceRequest { workspace: workspace.as_ref().to_string() })

View file

@ -1,30 +1,8 @@
#[deprecated = "use underlying errors to provide more context on what errors could really be thrown"]
#[allow(deprecated)]
pub type Result<T> = std::result::Result<T, Error>;
#[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<T> = std::result::Result<T, ProcedureError>;
pub type RemoteResult<T> = std::result::Result<T, RemoteError>;
#[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<ProcedureError> for ConnectionError {
fn from(value: ProcedureError) -> Self {
match value {
ProcedureError::Server(x) => Self::Procedure(x)
}
impl From<tonic::Status> for ConnectionError {
fn from(value: tonic::Status) -> Self {
Self::Remote(RemoteError(value))
}
}

View file

@ -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<Vec<User>> {
pub async fn list_buffer_users(&self, path: &str) -> RemoteResult<Vec<User>> {
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 {