chore: map error
This commit is contained in:
parent
1b17c8586b
commit
971aa6d3e1
|
|
@ -12,8 +12,6 @@ use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
pub const CONTROL_STREAM_KEY: &str = "af_collab_control";
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CollabRedisStream {
|
pub struct CollabRedisStream {
|
||||||
connection_manager: ConnectionManager,
|
connection_manager: ConnectionManager,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use app_error::AppError;
|
||||||
use collab::error::CollabError;
|
use collab::error::CollabError;
|
||||||
use collab_stream::error::StreamError;
|
use collab_stream::error::StreamError;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
@ -61,6 +62,21 @@ pub enum RealtimeError {
|
||||||
#[error("Collab redis stream error: {0}")]
|
#[error("Collab redis stream error: {0}")]
|
||||||
StreamError(#[from] StreamError),
|
StreamError(#[from] StreamError),
|
||||||
|
|
||||||
|
#[error("Cannot create group: {0}")]
|
||||||
|
CannotCreateGroup(String),
|
||||||
|
|
||||||
|
#[error("BinCodeCollab error: {0}")]
|
||||||
|
BincodeEncode(String),
|
||||||
|
|
||||||
|
#[error("Failed to create snapshot: {0}")]
|
||||||
|
CreateSnapshotFailed(String),
|
||||||
|
|
||||||
|
#[error("Failed to get latest snapshot: {0}")]
|
||||||
|
GetLatestSnapshotFailed(String),
|
||||||
|
|
||||||
|
#[error("Collab Schema Error: {0}")]
|
||||||
|
CollabSchemaError(String),
|
||||||
|
|
||||||
#[error("failed to obtain lease: {0}")]
|
#[error("failed to obtain lease: {0}")]
|
||||||
Lease(Box<dyn std::error::Error + Send + Sync>),
|
Lease(Box<dyn std::error::Error + Send + Sync>),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ impl CollabGroup {
|
||||||
.state
|
.state
|
||||||
.collab_type
|
.collab_type
|
||||||
.validate_require_data(collab)
|
.validate_require_data(collab)
|
||||||
.map_err(|err| RealtimeError::Internal(err.into()))
|
.map_err(|err| RealtimeError::CollabSchemaError(err.to_string()))
|
||||||
})?;
|
})?;
|
||||||
Ok(encode_collab)
|
Ok(encode_collab)
|
||||||
}
|
}
|
||||||
|
|
@ -1159,7 +1159,7 @@ impl CollabPersister {
|
||||||
.storage
|
.storage
|
||||||
.create_snapshot(params)
|
.create_snapshot(params)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| RealtimeError::Internal(err.into()))?;
|
.map_err(|err| RealtimeError::CreateSnapshotFailed(err.to_string()))?;
|
||||||
|
|
||||||
// 2. Generate document state with GC turned on and save it.
|
// 2. Generate document state with GC turned on and save it.
|
||||||
tx.force_gc();
|
tx.force_gc();
|
||||||
|
|
@ -1239,12 +1239,12 @@ impl CollabPersister {
|
||||||
self.collab_type.clone(),
|
self.collab_type.clone(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| RealtimeError::Internal(err.into()))?;
|
.map_err(|err| RealtimeError::GetLatestSnapshotFailed(err.to_string()))?;
|
||||||
match snapshot {
|
match snapshot {
|
||||||
None => None,
|
None => None,
|
||||||
Some(snapshot) => {
|
Some(snapshot) => {
|
||||||
let encoded_collab = EncodedCollab::decode_from_bytes(&snapshot.encoded_collab_v1)
|
let encoded_collab = EncodedCollab::decode_from_bytes(&snapshot.encoded_collab_v1)
|
||||||
.map_err(|err| RealtimeError::Internal(err.into()))?;
|
.map_err(|err| RealtimeError::BincodeEncode(err.to_string()))?;
|
||||||
Some(encoded_collab.doc_state)
|
Some(encoded_collab.doc_state)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ where
|
||||||
.transact()
|
.transact()
|
||||||
.state_vector(),
|
.state_vector(),
|
||||||
Err(err) if err.is_record_not_found() => StateVector::default(),
|
Err(err) if err.is_record_not_found() => StateVector::default(),
|
||||||
Err(err) => return Err(RealtimeError::Internal(err.into())),
|
Err(err) => return Err(RealtimeError::CannotCreateGroup(err.to_string())),
|
||||||
};
|
};
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue