Skip to content

Commit

Permalink
fix(cli): make dynamic import errors catchable (denoland#8750)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Dec 15, 2020
1 parent b6d5ae1 commit 63a821b
Show file tree
Hide file tree
Showing 16 changed files with 447 additions and 270 deletions.
24 changes: 9 additions & 15 deletions cli/disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl DiskCache {
})
}

pub fn get_cache_filename(&self, url: &Url) -> PathBuf {
fn get_cache_filename(&self, url: &Url) -> Option<PathBuf> {
let mut out = PathBuf::new();

let scheme = url.scheme();
Expand Down Expand Up @@ -105,31 +105,25 @@ impl DiskCache {

out = out.join(remaining_components);
}
scheme => {
unimplemented!(
"Don't know how to create cache name for scheme: {}\n Url: {}",
scheme,
url
);
}
_ => return None,
};

out
Some(out)
}

pub fn get_cache_filename_with_extension(
&self,
url: &Url,
extension: &str,
) -> PathBuf {
let base = self.get_cache_filename(url);
) -> Option<PathBuf> {
let base = self.get_cache_filename(url)?;

match base.extension() {
None => base.with_extension(extension),
None => Some(base.with_extension(extension)),
Some(ext) => {
let original_extension = OsStr::to_str(ext).unwrap();
let final_extension = format!("{}.{}", original_extension, extension);
base.with_extension(final_extension)
Some(base.with_extension(final_extension))
}
}
}
Expand Down Expand Up @@ -234,7 +228,7 @@ mod tests {
for test_case in &test_cases {
let cache_filename =
cache.get_cache_filename(&Url::parse(test_case.0).unwrap());
assert_eq!(cache_filename, PathBuf::from(test_case.1));
assert_eq!(cache_filename, Some(PathBuf::from(test_case.1)));
}
}

Expand Down Expand Up @@ -280,7 +274,7 @@ mod tests {
&Url::parse(test_case.0).unwrap(),
test_case.1
),
PathBuf::from(test_case.2)
Some(PathBuf::from(test_case.2))
)
}
}
Expand Down
Loading

0 comments on commit 63a821b

Please sign in to comment.