chore: optimize the UI if fail to open the workspace (#3246)

* chore: async load user profile

* chore: enable reset workspace

* chore: add confirm dialog
This commit is contained in:
Nathan.fooo
2023-08-22 00:19:15 +08:00
committed by GitHub
parent bd30e31f6c
commit 12d6cbd46a
64 changed files with 928 additions and 322 deletions

View File

@ -3,9 +3,12 @@ use thiserror::Error;
use flowy_derive::ProtoBuf_Enum;
#[derive(Debug, Clone, PartialEq, Eq, Error, Serialize_repr, Deserialize_repr, ProtoBuf_Enum)]
#[derive(
Debug, Default, Clone, PartialEq, Eq, Error, Serialize_repr, Deserialize_repr, ProtoBuf_Enum,
)]
#[repr(u8)]
pub enum ErrorCode {
#[default]
#[error("Internal error")]
Internal = 0,
@ -226,6 +229,9 @@ pub enum ErrorCode {
#[error("It appears that the collaboration object's data has not been fully synchronized")]
CollabDataNotSync = 75,
#[error("It appears that the workspace data has not been fully synchronized")]
WorkspaceDataNotSync = 76,
}
impl ErrorCode {

View File

@ -1,6 +1,7 @@
use std::convert::TryInto;
use std::fmt::Debug;
use anyhow::Result;
use protobuf::ProtobufError;
use thiserror::Error;
use flowy_derive::ProtoBuf;
@ -13,10 +14,13 @@ pub type FlowyResult<T> = anyhow::Result<T, FlowyError>;
#[error("{code:?}: {msg}")]
pub struct FlowyError {
#[pb(index = 1)]
pub code: i32,
pub code: ErrorCode,
#[pb(index = 2)]
pub msg: String,
#[pb(index = 3)]
pub payload: Vec<u8>,
}
macro_rules! static_flowy_error {
@ -31,17 +35,23 @@ macro_rules! static_flowy_error {
impl FlowyError {
pub fn new<T: ToString>(code: ErrorCode, msg: T) -> Self {
Self {
code: code.value(),
code,
msg: msg.to_string(),
payload: vec![],
}
}
pub fn context<T: Debug>(mut self, error: T) -> Self {
pub fn with_context<T: Debug>(mut self, error: T) -> Self {
self.msg = format!("{:?}", error);
self
}
pub fn with_payload<T: TryInto<Vec<u8>, Error = ProtobufError>>(mut self, payload: T) -> Self {
self.payload = payload.try_into().unwrap_or_default();
self
}
pub fn is_record_not_found(&self) -> bool {
self.code == ErrorCode::RecordNotFound.value()
self.code == ErrorCode::RecordNotFound
}
static_flowy_error!(internal, ErrorCode::Internal);
@ -93,9 +103,11 @@ impl FlowyError {
impl std::convert::From<ErrorCode> for FlowyError {
fn from(code: ErrorCode) -> Self {
let msg = format!("{}", code);
FlowyError {
code: code.value(),
msg: format!("{}", code),
code,
msg,
payload: vec![],
}
}
}
@ -104,18 +116,18 @@ pub fn internal_error<T>(e: T) -> FlowyError
where
T: std::fmt::Debug,
{
FlowyError::internal().context(e)
FlowyError::internal().with_context(e)
}
impl std::convert::From<std::io::Error> for FlowyError {
fn from(error: std::io::Error) -> Self {
FlowyError::internal().context(error)
FlowyError::internal().with_context(error)
}
}
impl std::convert::From<protobuf::ProtobufError> for FlowyError {
fn from(e: protobuf::ProtobufError) -> Self {
FlowyError::internal().context(e)
FlowyError::internal().with_context(e)
}
}

View File

@ -1,15 +1,16 @@
use crate::FlowyError;
use collab_database::error::DatabaseError;
use collab_document::error::DocumentError;
use crate::FlowyError;
impl From<DatabaseError> for FlowyError {
fn from(error: DatabaseError) -> Self {
FlowyError::internal().context(error)
FlowyError::internal().with_context(error)
}
}
impl From<DocumentError> for FlowyError {
fn from(error: DocumentError) -> Self {
FlowyError::internal().context(error)
FlowyError::internal().with_context(error)
}
}

View File

@ -2,12 +2,12 @@ use crate::FlowyError;
impl std::convert::From<flowy_sqlite::Error> for FlowyError {
fn from(error: flowy_sqlite::Error) -> Self {
FlowyError::internal().context(error)
FlowyError::internal().with_context(error)
}
}
impl std::convert::From<::r2d2::Error> for FlowyError {
fn from(error: r2d2::Error) -> Self {
FlowyError::internal().context(error)
FlowyError::internal().with_context(error)
}
}

View File

@ -1,7 +1,11 @@
use crate::FlowyError;
use bytes::Bytes;
use lib_dispatch::prelude::{AFPluginEventResponse, ResponseBuilder};
use std::convert::TryInto;
use bytes::Bytes;
use lib_dispatch::prelude::{AFPluginEventResponse, ResponseBuilder};
use crate::FlowyError;
impl lib_dispatch::Error for FlowyError {
fn as_response(&self) -> AFPluginEventResponse {
let bytes: Bytes = self.clone().try_into().unwrap();

View File

@ -2,6 +2,6 @@ use crate::FlowyError;
impl std::convert::From<tokio_postgres::Error> for FlowyError {
fn from(error: tokio_postgres::Error) -> Self {
FlowyError::internal().context(error)
FlowyError::internal().with_context(error)
}
}

View File

@ -1,8 +1,9 @@
use crate::FlowyError;
use reqwest::Error;
use crate::FlowyError;
impl std::convert::From<reqwest::Error> for FlowyError {
fn from(error: Error) -> Self {
FlowyError::http().context(error)
FlowyError::http().with_context(error)
}
}

View File

@ -2,6 +2,6 @@ use crate::FlowyError;
impl std::convert::From<serde_json::Error> for FlowyError {
fn from(error: serde_json::Error) -> Self {
FlowyError::serde().context(error)
FlowyError::serde().with_context(error)
}
}