fix: updated js and py glues with new errors

This commit is contained in:
əlemi 2024-09-05 02:33:35 +02:00 committed by zaaarf
parent d25e744a37
commit 921a8ee69a
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
8 changed files with 56 additions and 35 deletions

2
dist/py/codemp.pyi vendored
View file

@ -79,7 +79,7 @@ class BufferController:
Handle to the controller for a specific buffer, which manages the back and forth Handle to the controller for a specific buffer, which manages the back and forth
of operations to and from other peers. of operations to and from other peers.
""" """
def name(self) -> str: ... def path(self) -> str: ...
def content(self) -> Promise[str]: ... def content(self) -> Promise[str]: ...
def send(self, def send(self,
start: int, start: int,

View file

@ -33,9 +33,9 @@ impl BufferController {
} }
#[napi(js_name = "get_name")] #[napi(js_name = "get_path")]
pub fn js_name(&self) -> napi::Result<&str> { pub fn js_path(&self) -> napi::Result<&str> {
Ok(&self.name()) Ok(&self.path())
} }
#[napi(js_name = "poll")] #[napi(js_name = "poll")]

View file

@ -1,5 +1,5 @@
use napi_derive::napi; use napi_derive::napi;
use crate::hash; use crate::ext::hash;
#[napi(js_name = "hash")] #[napi(js_name = "hash")]

View file

@ -10,13 +10,21 @@ pub mod op_cache;
pub mod ext; pub mod ext;
impl From<crate::Error> for napi::Error { impl From<crate::errors::ConnectionError> for napi::Error {
fn from(value: crate::Error) -> Self { fn from(value: crate::errors::ConnectionError) -> Self {
let msg = format!("{value}"); napi::Error::new(napi::Status::GenericFailure, format!("{value}"))
match value { }
crate::Error::Deadlocked => napi::Error::new(napi::Status::WouldDeadlock, msg), }
_ => napi::Error::new(napi::Status::GenericFailure, msg),
} impl From<crate::errors::RemoteError> for napi::Error {
fn from(value: crate::errors::RemoteError) -> Self {
napi::Error::new(napi::Status::GenericFailure, format!("{value}"))
}
}
impl From<crate::errors::ControllerError> for napi::Error {
fn from(value: crate::errors::ControllerError) -> Self {
napi::Error::new(napi::Status::GenericFailure, format!("{value}"))
} }
} }

View file

@ -4,9 +4,21 @@ use pyo3::prelude::*;
#[pymethods] #[pymethods]
impl Client { impl Client {
// #[new] #[new]
// fn __new__(host: String, username: String, password: String) -> crate::Result<Self> { fn __new__(host: String, username: String, password: String) -> crate::errors::ConnectionResult<Self> {
// tokio().block_on(Client::connect(host, username, password)) tokio().block_on(Client::connect(host, username, password))
}
// #[pyo3(name = "join_workspace")]
// async fn pyjoin_workspace(&self, workspace: String) -> JoinHandle<crate::Result<Workspace>> {
// tracing::info!("attempting to join the workspace {}", workspace);
// let this = self.clone();
// async {
// tokio()
// .spawn(async move { this.join_workspace(workspace).await })
// .await
// }
// } // }
#[pyo3(name = "join_workspace")] #[pyo3(name = "join_workspace")]

View file

@ -74,9 +74,9 @@ impl CursorController {
// need to do manually since Controller is a trait implementation // need to do manually since Controller is a trait implementation
#[pymethods] #[pymethods]
impl BufferController { impl BufferController {
#[pyo3(name = "name")] #[pyo3(name = "path")]
fn pyname(&self) -> String { fn pypath(&self) -> String {
self.name().to_string() self.path().to_string()
} }
#[pyo3(name = "content")] #[pyo3(name = "content")]

View file

@ -195,20 +195,21 @@ fn set_logger(logging_cb: Py<PyFunction>, debug: bool) -> bool {
log_subscribed log_subscribed
} }
impl From<crate::Error> for PyErr { impl From<crate::errors::ConnectionError> for PyErr {
fn from(value: crate::Error) -> Self { fn from(value: crate::errors::ConnectionError) -> Self {
match value { PyConnectionError::new_err(format!("Connection error: {value}"))
crate::Error::Transport { status, message } => { }
PyConnectionError::new_err(format!("Transport error: ({}) {}", status, message)) }
}
crate::Error::Channel { send } => { impl From<crate::errors::RemoteError> for PyErr {
PyConnectionError::new_err(format!("Channel error (send:{})", send)) fn from(value: crate::errors::RemoteError) -> Self {
} PyRuntimeError::new_err(format!("Remote error: {value}"))
crate::Error::InvalidState { msg } => { }
PyRuntimeError::new_err(format!("Invalid state: {}", msg)) }
}
crate::Error::Deadlocked => PyRuntimeError::new_err("Deadlock, retry."), impl From<crate::errors::ControllerError> for PyErr {
} fn from(value: crate::errors::ControllerError) -> Self {
PyRuntimeError::new_err(format!("Controller error: {value}"))
} }
} }

View file

@ -24,9 +24,9 @@ impl Workspace {
#[pyo3(name = "detach")] #[pyo3(name = "detach")]
fn pydetach(&self, path: String) -> bool { fn pydetach(&self, path: String) -> bool {
match self.detach(path.as_str()) { match self.detach(path.as_str()) {
crate::workspace::worker::DetachResult::NotAttached => false, crate::workspace::DetachResult::NotAttached => false,
crate::workspace::worker::DetachResult::Detaching => true, crate::workspace::DetachResult::Detaching => true,
crate::workspace::worker::DetachResult::AlreadyDetached => true, crate::workspace::DetachResult::AlreadyDetached => true,
} }
} }