diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-08-26 00:22:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-26 00:22:15 +0200 |
commit | 9bfb0df805719cb3f022a5b5d9f9d898ae954c2e (patch) | |
tree | 6c7d62d95fcbde54ebbe1035bdc74618c63cfbc0 /cli/file_fetcher.rs | |
parent | d0ccab7fb7dd80030d3765ca9a9af44de6ecda5a (diff) |
refactor: remove OpError, use ErrBox everywhere (#7187)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/file_fetcher.rs')
-rw-r--r-- | cli/file_fetcher.rs | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index c703bfc27..c5fd78897 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -5,7 +5,6 @@ use crate::http_util; use crate::http_util::create_http_client; use crate::http_util::FetchOnceResult; use crate::msg; -use crate::op_error::OpError; use crate::permissions::Permissions; use crate::text_encoding; use deno_core::ErrBox; @@ -138,11 +137,12 @@ impl SourceFileFetcher { pub fn check_if_supported_scheme(url: &Url) -> Result<(), ErrBox> { if !SUPPORTED_URL_SCHEMES.contains(&url.scheme()) { - return Err( - OpError::other( - format!("Unsupported scheme \"{}\" for module \"{}\". Supported schemes: {:#?}", url.scheme(), url, SUPPORTED_URL_SCHEMES), - ).into() - ); + return Err(ErrBox::error(format!( + "Unsupported scheme \"{}\" for module \"{}\". Supported schemes: {:#?}", + url.scheme(), + url, + SUPPORTED_URL_SCHEMES + ))); } Ok(()) @@ -255,13 +255,13 @@ impl SourceFileFetcher { r#"Cannot find module "{}"{} in cache, --cached-only is specified"#, module_url, referrer_suffix ); - OpError::not_found(msg).into() + ErrBox::new("NotFound", msg) } else if is_not_found { let msg = format!( r#"Cannot resolve module "{}"{}"#, module_url, referrer_suffix ); - OpError::not_found(msg).into() + ErrBox::new("NotFound", msg) } else { err }; @@ -346,9 +346,7 @@ impl SourceFileFetcher { permissions: &Permissions, ) -> Result<SourceFile, ErrBox> { let filepath = module_url.to_file_path().map_err(|()| { - ErrBox::from(OpError::uri_error( - "File URL contains invalid path".to_owned(), - )) + ErrBox::new("URIError", "File URL contains invalid path") })?; permissions.check_read(&filepath)?; @@ -385,8 +383,7 @@ impl SourceFileFetcher { redirect_limit: i64, ) -> Result<Option<SourceFile>, ErrBox> { if redirect_limit < 0 { - let e = OpError::http("too many redirects".to_string()); - return Err(e.into()); + return Err(ErrBox::new("Http", "too many redirects")); } let result = self.http_cache.get(&module_url); @@ -451,12 +448,12 @@ impl SourceFileFetcher { permissions: &Permissions, ) -> Pin<Box<dyn Future<Output = Result<SourceFile, ErrBox>>>> { if redirect_limit < 0 { - let e = OpError::http("too many redirects".to_string()); - return futures::future::err(e.into()).boxed_local(); + let e = ErrBox::new("Http", "too many redirects"); + return futures::future::err(e).boxed_local(); } if let Err(e) = permissions.check_net_url(&module_url) { - return futures::future::err(e.into()).boxed_local(); + return futures::future::err(e).boxed_local(); } let is_blocked = @@ -479,17 +476,12 @@ impl SourceFileFetcher { // If file wasn't found in cache check if we can fetch it if cached_only { // We can't fetch remote file - bail out - return futures::future::err( - std::io::Error::new( - std::io::ErrorKind::NotFound, - format!( - "Cannot find remote file '{}' in cache, --cached-only is specified", - module_url.to_string() - ), - ) - .into(), - ) - .boxed_local(); + let message = format!( + "Cannot find remote file '{}' in cache, --cached-only is specified", + module_url + ); + return futures::future::err(ErrBox::new("NotFound", message)) + .boxed_local(); } info!("{} {}", colors::green("Download"), module_url.to_string()); |