mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
fix: updated js and py glues with new errors
This commit is contained in:
parent
d25e744a37
commit
921a8ee69a
8 changed files with 56 additions and 35 deletions
2
dist/py/codemp.pyi
vendored
2
dist/py/codemp.pyi
vendored
|
@ -79,7 +79,7 @@ class BufferController:
|
|||
Handle to the controller for a specific buffer, which manages the back and forth
|
||||
of operations to and from other peers.
|
||||
"""
|
||||
def name(self) -> str: ...
|
||||
def path(self) -> str: ...
|
||||
def content(self) -> Promise[str]: ...
|
||||
def send(self,
|
||||
start: int,
|
||||
|
|
|
@ -33,9 +33,9 @@ impl BufferController {
|
|||
}
|
||||
|
||||
|
||||
#[napi(js_name = "get_name")]
|
||||
pub fn js_name(&self) -> napi::Result<&str> {
|
||||
Ok(&self.name())
|
||||
#[napi(js_name = "get_path")]
|
||||
pub fn js_path(&self) -> napi::Result<&str> {
|
||||
Ok(&self.path())
|
||||
}
|
||||
|
||||
#[napi(js_name = "poll")]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use napi_derive::napi;
|
||||
use crate::hash;
|
||||
use crate::ext::hash;
|
||||
|
||||
|
||||
#[napi(js_name = "hash")]
|
||||
|
|
|
@ -10,13 +10,21 @@ pub mod op_cache;
|
|||
pub mod ext;
|
||||
|
||||
|
||||
impl From<crate::Error> for napi::Error {
|
||||
fn from(value: crate::Error) -> Self {
|
||||
let msg = 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::ConnectionError> for napi::Error {
|
||||
fn from(value: crate::errors::ConnectionError) -> Self {
|
||||
napi::Error::new(napi::Status::GenericFailure, format!("{value}"))
|
||||
}
|
||||
}
|
||||
|
||||
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}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,21 @@ use pyo3::prelude::*;
|
|||
|
||||
#[pymethods]
|
||||
impl Client {
|
||||
// #[new]
|
||||
// fn __new__(host: String, username: String, password: String) -> crate::Result<Self> {
|
||||
// tokio().block_on(Client::connect(host, username, password))
|
||||
#[new]
|
||||
fn __new__(host: String, username: String, password: String) -> crate::errors::ConnectionResult<Self> {
|
||||
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")]
|
||||
|
|
|
@ -74,9 +74,9 @@ impl CursorController {
|
|||
// need to do manually since Controller is a trait implementation
|
||||
#[pymethods]
|
||||
impl BufferController {
|
||||
#[pyo3(name = "name")]
|
||||
fn pyname(&self) -> String {
|
||||
self.name().to_string()
|
||||
#[pyo3(name = "path")]
|
||||
fn pypath(&self) -> String {
|
||||
self.path().to_string()
|
||||
}
|
||||
|
||||
#[pyo3(name = "content")]
|
||||
|
|
|
@ -195,20 +195,21 @@ fn set_logger(logging_cb: Py<PyFunction>, debug: bool) -> bool {
|
|||
log_subscribed
|
||||
}
|
||||
|
||||
impl From<crate::Error> for PyErr {
|
||||
fn from(value: crate::Error) -> Self {
|
||||
match value {
|
||||
crate::Error::Transport { status, message } => {
|
||||
PyConnectionError::new_err(format!("Transport error: ({}) {}", status, message))
|
||||
impl From<crate::errors::ConnectionError> for PyErr {
|
||||
fn from(value: crate::errors::ConnectionError) -> Self {
|
||||
PyConnectionError::new_err(format!("Connection error: {value}"))
|
||||
}
|
||||
crate::Error::Channel { send } => {
|
||||
PyConnectionError::new_err(format!("Channel error (send:{})", send))
|
||||
}
|
||||
crate::Error::InvalidState { msg } => {
|
||||
PyRuntimeError::new_err(format!("Invalid state: {}", msg))
|
||||
}
|
||||
crate::Error::Deadlocked => PyRuntimeError::new_err("Deadlock, retry."),
|
||||
}
|
||||
|
||||
impl From<crate::errors::RemoteError> for PyErr {
|
||||
fn from(value: crate::errors::RemoteError) -> Self {
|
||||
PyRuntimeError::new_err(format!("Remote error: {value}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::errors::ControllerError> for PyErr {
|
||||
fn from(value: crate::errors::ControllerError) -> Self {
|
||||
PyRuntimeError::new_err(format!("Controller error: {value}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ impl Workspace {
|
|||
#[pyo3(name = "detach")]
|
||||
fn pydetach(&self, path: String) -> bool {
|
||||
match self.detach(path.as_str()) {
|
||||
crate::workspace::worker::DetachResult::NotAttached => false,
|
||||
crate::workspace::worker::DetachResult::Detaching => true,
|
||||
crate::workspace::worker::DetachResult::AlreadyDetached => true,
|
||||
crate::workspace::DetachResult::NotAttached => false,
|
||||
crate::workspace::DetachResult::Detaching => true,
|
||||
crate::workspace::DetachResult::AlreadyDetached => true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue