Skip to content

Commit

Permalink
perf: remove expect to prevent panics
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilerd committed May 14, 2024
1 parent 7b22fcd commit c7e3f4c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions zhang-cli/src/opendal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ impl DataSource for OpendalDataSource {
}

fn get(&self, path: String) -> ZhangResult<Vec<u8>> {
Ok(self.operator.blocking().read(path.as_str()).expect("cannot read file").to_vec())
self.operator
.blocking()
.read(path.as_str())
.map(|data| data.to_vec())
.map_err(|e| ZhangError::CustomError(format!("fail to get file content [{}] : {}", path, e)))
}

async fn async_load(&self, entry: String, endpoint: String) -> ZhangResult<LoadResult> {
Expand Down Expand Up @@ -79,8 +83,7 @@ impl DataSource for OpendalDataSource {
if err.kind() == ErrorKind::NotFound {
Ok(Vec::new())
} else {
error!("cannot get content from {}: {}", &path, &err);
Err(ZhangError::CustomError("error on getting file content".to_owned()))
Err(ZhangError::CustomError(format!("Error getting file content from {}: {}", path, err)))
}
}
}
Expand Down

0 comments on commit c7e3f4c

Please sign in to comment.