Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
add context to errors in syncdir (#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc-msft authored Jun 16, 2021
1 parent c71ce58 commit 5efc4f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/agent/onefuzz/src/blob/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ impl BlobContainerUrl {
pub fn url(&self) -> Result<Url> {
match self {
Self::BlobContainer(url) => Ok(url.clone()),
Self::Path(p) => Ok(Url::from_file_path(p).map_err(|_| anyhow!("invalid path"))?),
Self::Path(p) => Ok(Url::from_file_path(p)
.map_err(|err| anyhow!("invalid path. path:{} error:{:?}", p.display(), err))?),
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/agent/onefuzz/src/syncdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ pub struct SyncedDir {
impl SyncedDir {
pub fn remote_url(&self) -> Result<BlobContainerUrl> {
let url = self.remote_path.clone().unwrap_or(BlobContainerUrl::new(
Url::from_file_path(self.local_path.clone()).map_err(|_| anyhow!("invalid path"))?,
Url::from_file_path(self.local_path.clone()).map_err(|err| {
anyhow!(
"invalid path: {} error:{:?}",
self.local_path.display(),
err
)
})?,
)?);
Ok(url)
}
Expand Down Expand Up @@ -89,7 +95,9 @@ impl SyncedDir {

pub async fn init(&self) -> Result<()> {
if let Some(remote_path) = self.remote_path.clone().and_then(|u| u.as_file_path()) {
fs::create_dir_all(remote_path).await?;
fs::create_dir_all(&remote_path).await.with_context(|| {
format!("unable to create directory: {}", remote_path.display())
})?;
}

match fs::metadata(&self.local_path).await {
Expand Down

0 comments on commit 5efc4f9

Please sign in to comment.