mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 15:34:49 +01:00
fix: better error handling
This commit is contained in:
parent
dd0acdad2f
commit
c1b7073e89
2 changed files with 16 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
||||||
use codemp::proto::{RawOp, OperationRequest};
|
use codemp::proto::{RawOp, OperationRequest};
|
||||||
use tokio::sync::{mpsc, broadcast, watch};
|
use tokio::sync::{mpsc, broadcast, watch};
|
||||||
use tracing::error;
|
use tracing::{error, warn};
|
||||||
use md5::Digest;
|
use md5::Digest;
|
||||||
|
|
||||||
use operational_transform::OperationSeq;
|
use operational_transform::OperationSeq;
|
||||||
|
@ -69,23 +69,27 @@ impl BufferWorker {
|
||||||
async fn work(mut self) {
|
async fn work(mut self) {
|
||||||
loop {
|
loop {
|
||||||
match self.edits.recv().await {
|
match self.edits.recv().await {
|
||||||
None => break,
|
None => break warn!("channel closed"),
|
||||||
Some(v) => {
|
Some(v) => match serde_json::from_str::<OperationSeq>(&v.opseq) {
|
||||||
let op : OperationSeq = serde_json::from_str(&v.opseq).unwrap();
|
Err(e) => break error!("could not deserialize opseq: {}", e),
|
||||||
match op.apply(&self.store) {
|
Ok(op) => match op.apply(&self.store) {
|
||||||
|
Err(e) => error!("coult not apply OpSeq '{:?}' on '{}' : {}", v, self.store, e),
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
self.store = res;
|
self.store = res;
|
||||||
self.digest.send(md5::compute(&self.store)).unwrap();
|
|
||||||
self.content.send(self.store.clone()).unwrap();
|
|
||||||
let msg = RawOp {
|
let msg = RawOp {
|
||||||
opseq: v.opseq,
|
opseq: v.opseq,
|
||||||
user: v.user
|
user: v.user
|
||||||
};
|
};
|
||||||
|
if let Err(e) = self.digest.send(md5::compute(&self.store)) {
|
||||||
|
error!("could not update digest: {}", e);
|
||||||
|
}
|
||||||
|
if let Err(e) = self.content.send(self.store.clone()) {
|
||||||
|
error!("could not update content: {}", e);
|
||||||
|
}
|
||||||
if let Err(e) = self.events.send(msg) {
|
if let Err(e) = self.events.send(msg) {
|
||||||
error!("could not broadcast OpSeq: {}", e);
|
error!("could not broadcast OpSeq: {}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => error!("coult not apply OpSeq '{:?}' on '{}' : {}", v, self.store, e),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,10 @@ impl Buffer for BufferService {
|
||||||
None => return Err(Status::not_found("path not found")),
|
None => return Err(Status::not_found("path not found")),
|
||||||
};
|
};
|
||||||
info!("sending edit to buffer: {}", request.opseq);
|
info!("sending edit to buffer: {}", request.opseq);
|
||||||
tx.send(request).await.unwrap();
|
match tx.send(request).await {
|
||||||
Ok(Response::new(BufferResponse { accepted: true, content: None }))
|
Ok(()) => Ok(Response::new(BufferResponse { accepted: true, content: None })),
|
||||||
|
Err(e) => Err(Status::internal(format!("error sending edit to buffer actor: {}", e))),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(&self, req:Request<BufferPayload>) -> Result<Response<BufferResponse>, Status> {
|
async fn create(&self, req:Request<BufferPayload>) -> Result<Response<BufferResponse>, Status> {
|
||||||
|
|
Loading…
Reference in a new issue