Skip to content

Commit

Permalink
Merge pull request #315 from zhang-accounting/fix/cache-folder-should…
Browse files Browse the repository at this point in the history
…-runs-on-async

refact: add custom error
  • Loading branch information
Kilerd authored May 6, 2024
2 parents 0c1dd2f + 712a100 commit 558ec44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 3 additions & 7 deletions zhang-cli/src/opendal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use async_recursion::async_recursion;
use beancount::Beancount;
use log::{debug, error, info};
use opendal::services::{Fs, Webdav};
use opendal::{ErrorKind, Operator};
use opendal::Operator;
use zhang_ast::{Directive, Include, SpanInfo, Spanned, ZhangString};
use zhang_core::data_source::{DataSource, LoadResult};
use zhang_core::data_type::text::parser::parse as zhang_parse;
Expand Down Expand Up @@ -77,12 +77,8 @@ impl DataSource for OpendalDataSource {
match result {
Ok(data) => Ok(data),
Err(err) => {
if err.kind() == ErrorKind::NotFound {
Ok(Vec::new())
} else {
error!("cannot get content from {}: {}", &path, &err);
Ok(Vec::new())
}
error!("cannot get content from {}: {}", &path, &err);
Err(ZhangError::CustomError("error on getting file content"))
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions zhang-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub enum ZhangError {

#[error("invalid content encoding: {0}")]
ContentEncodingError(#[from] std::string::FromUtf8Error),

#[error("custom error: {0}")]
CustomError(&'static str),
}

pub trait IoErrorIntoZhangError<T> {
Expand Down
8 changes: 4 additions & 4 deletions zhang-server/src/routes/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ pub async fn download_document(ledger: State<Arc<RwLock<Ledger>>>, path: Path<(S
let filename = String::from_utf8(BASE64_STANDARD.decode(&encoded_file_path).unwrap()).unwrap();
let ledger = ledger.read().await;
let entry = &ledger.entry.0;
let full_path = entry.join(filename);
let striped_path = full_path.strip_prefix(entry).unwrap();
let file_name = striped_path.file_name().unwrap().to_string_lossy().to_string();
let full_path = dbg!(entry.join(filename));

Check failure on line 23 in zhang-server/src/routes/document.rs

View workflow job for this annotation

GitHub Actions / clippy-check

the `dbg!` macro is intended as a debugging tool
let striped_path = dbg!(full_path.strip_prefix(entry).unwrap());

Check failure on line 24 in zhang-server/src/routes/document.rs

View workflow job for this annotation

GitHub Actions / clippy-check

the `dbg!` macro is intended as a debugging tool
let file_name = dbg!(striped_path.file_name().unwrap().to_string_lossy().to_string());

Check failure on line 25 in zhang-server/src/routes/document.rs

View workflow job for this annotation

GitHub Actions / clippy-check

the `dbg!` macro is intended as a debugging tool
let content = cacheable_data(&encoded_file_path, async {
info!("loading file [{:?}] data from remote...", &striped_path);
ledger.data_source.async_get(striped_path.to_string_lossy().to_string()).await
ledger.data_source.async_get(dbg!(striped_path.to_string_lossy().to_string())).await

Check failure on line 28 in zhang-server/src/routes/document.rs

View workflow job for this annotation

GitHub Actions / clippy-check

the `dbg!` macro is intended as a debugging tool
})
.await
.expect("cannot get file data");
Expand Down

0 comments on commit 558ec44

Please sign in to comment.