refactor: rename && fix potential bugs

This commit is contained in:
appflowy 2022-09-10 10:05:27 +08:00
parent 2d44a9a956
commit 328e0ac73a
4 changed files with 75 additions and 80 deletions

View file

@ -25,11 +25,8 @@ impl std::convert::From<OTErrorCode> for OTError {
}
impl OTError {
pub fn new(code: OTErrorCode, msg: &str) -> OTError {
Self {
code,
msg: msg.to_owned(),
}
pub fn new(code: OTErrorCode, msg: String) -> OTError {
Self { code, msg }
}
pub fn context<T: Debug>(mut self, error: T) -> Self {
@ -76,6 +73,7 @@ pub enum OTErrorCode {
Internal,
PathNotFound,
PathIsEmpty,
UnexpectedEmpty,
}
pub struct ErrorBuilder {
@ -105,6 +103,6 @@ impl ErrorBuilder {
}
pub fn build(mut self) -> OTError {
OTError::new(self.code, &self.msg.take().unwrap_or_else(|| "".to_owned()))
OTError::new(self.code, self.msg.take().unwrap_or_else(|| "".to_owned()))
}
}