diff --git a/zhang-cli/src/opendal.rs b/zhang-cli/src/opendal.rs index 5d8ea4c8..fcc14839 100644 --- a/zhang-cli/src/opendal.rs +++ b/zhang-cli/src/opendal.rs @@ -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; @@ -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")) } } } diff --git a/zhang-core/src/error.rs b/zhang-core/src/error.rs index f3d800f9..843c73a3 100644 --- a/zhang-core/src/error.rs +++ b/zhang-core/src/error.rs @@ -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 { diff --git a/zhang-server/src/routes/document.rs b/zhang-server/src/routes/document.rs index ab9d6bca..34cb0017 100644 --- a/zhang-server/src/routes/document.rs +++ b/zhang-server/src/routes/document.rs @@ -20,12 +20,12 @@ pub async fn download_document(ledger: State>>, 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)); + let striped_path = dbg!(full_path.strip_prefix(entry).unwrap()); + let file_name = dbg!(striped_path.file_name().unwrap().to_string_lossy().to_string()); 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 }) .await .expect("cannot get file data");