Skip to content

Commit

Permalink
fix: Correctly determine a --cached-only error (denoland#3979)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Feb 12, 2020
1 parent e6167c7 commit 3563ab4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cli/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,20 @@ impl SourceFileFetcher {
} else {
"".to_owned()
};
let err = if err_kind == ErrorKind::NotFound {
// Hack: Check error message for "--cached-only" because the kind
// conflicts with other errors.
let err = if err.to_string().contains("--cached-only") {
let msg = format!(
r#"Cannot resolve module "{}"{}"#,
r#"Cannot find module "{}"{} in cache, --cached-only is specified"#,
module_url, referrer_suffix
);
DenoError::new(ErrorKind::NotFound, msg).into()
} else if err_kind == ErrorKind::PermissionDenied {
} else if err_kind == ErrorKind::NotFound {
let msg = format!(
r#"Cannot find module "{}"{} in cache, --cached-only is specified"#,
r#"Cannot resolve module "{}"{}"#,
module_url, referrer_suffix
);
DenoError::new(ErrorKind::PermissionDenied, msg).into()
DenoError::new(ErrorKind::NotFound, msg).into()
} else {
err
};
Expand Down Expand Up @@ -427,9 +429,9 @@ impl SourceFileFetcher {
// We can't fetch remote file - bail out
return futures::future::err(
std::io::Error::new(
std::io::ErrorKind::PermissionDenied,
std::io::ErrorKind::NotFound,
format!(
"cannot find remote file '{}' in cache",
"Cannot find remote file '{}' in cache, --cached-only is specified",
module_url.to_string()
),
)
Expand Down Expand Up @@ -1449,7 +1451,7 @@ mod tests {
.await;
assert!(result.is_err());
let err = result.err().unwrap();
assert_eq!(err.kind(), ErrorKind::PermissionDenied);
assert_eq!(err.kind(), ErrorKind::NotFound);

// download and cache file
let result = fetcher_1
Expand Down

0 comments on commit 3563ab4

Please sign in to comment.