Added errors wrappers and version bump

Former-commit-id: a9e1c1594f5d199499f7f08d273e2096f71f9bf1
This commit is contained in:
Camillo Schenone 2023-08-23 11:18:04 +02:00
parent c79529ce87
commit 31f296a55c
2 changed files with 31 additions and 10 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "CodempClient-Sublime" name = "CodempClient-Sublime"
version = "0.1.0" version = "0.2.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -9,7 +9,7 @@ name = "codemp_client"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.3" } codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.4.4" }
pyo3 = { version = "0.19", features = ["extension-module"] } pyo3 = { version = "0.19", features = ["extension-module"] }
pyo3-asyncio = { version = "0.19", features = ["tokio-runtime"] } pyo3-asyncio = { version = "0.19", features = ["tokio-runtime"] }
tokio = "1.29.1" tokio = "1.29.1"

View file

@ -1,18 +1,39 @@
use std::{sync::Arc, error::Error}; use std::{sync::Arc, error::Error, format};
use codemp::{ use codemp::prelude::*;
client::CodempClient, use codemp::errors::Error as CodempError;
controller::{cursor::{CursorSubscriber, CursorControllerHandle},
buffer::{OperationControllerHandle, OperationControllerSubscriber}}, use tokio::sync::Mutex;
proto::Position, factory::OperationFactory, tokio::sync::Mutex
};
use pyo3::{ use pyo3::{
prelude::*, prelude::*,
exceptions::PyConnectionError, exceptions::{PyConnectionError, PyRuntimeError},
types::{PyBool, PyString} types::{PyBool, PyString}
}; };
struct PyCodempError(CodempError);
impl From::<CodempError> for PyCodempError {
fn from(err: CodempError) -> Self {
PyCodempError(err)
}
}
impl std::convert::From<PyCodempError> for PyErr {
fn from(err: PyCodempError) -> PyErr {
match err.0 {
CodempError::Transport { status, message } => {
PyConnectionError::new_err(format!("Transport error: ({}) {}", status, message))
}
CodempError::Channel { send } => {
PyConnectionError::new_err(format!("Channel error (send:{})", send))
},
CodempError::InvalidState { msg } => {
PyRuntimeError::new_err(format!("Invalid state: {}", msg))
}
}
}
}
#[pyfunction] #[pyfunction]
fn connect<'a>(py: Python<'a>, dest: String) -> PyResult<&'a PyAny> { fn connect<'a>(py: Python<'a>, dest: String) -> PyResult<&'a PyAny> {
// construct a python coroutine // construct a python coroutine