summaryrefslogtreecommitdiff
path: root/cli/disk_cache.rs
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2020-01-24 14:16:31 -0800
committerRyan Dahl <ry@tinyclouds.org>2020-01-24 17:16:31 -0500
commit514cdd941c7c0e8166e9a6f06ee23ef8f7ef30d7 (patch)
tree365ad460b911c341d67a50ed311b8884e85aae5a /cli/disk_cache.rs
parent5e32c5ea448563be91017d71bab060c8a6bd90fe (diff)
Do not panic and improve error message on cache failure (#3784)
Diffstat (limited to 'cli/disk_cache.rs')
-rw-r--r--cli/disk_cache.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/cli/disk_cache.rs b/cli/disk_cache.rs
index a6689c6ec..bfef8ab64 100644
--- a/cli/disk_cache.rs
+++ b/cli/disk_cache.rs
@@ -13,6 +13,13 @@ pub struct DiskCache {
pub location: PathBuf,
}
+fn with_io_context<T: AsRef<str>>(
+ e: &std::io::Error,
+ context: T,
+) -> std::io::Error {
+ std::io::Error::new(e.kind(), format!("{} (for '{}')", e, context.as_ref()))
+}
+
impl DiskCache {
pub fn new(location: &Path) -> Self {
// TODO: ensure that 'location' is a directory
@@ -107,10 +114,12 @@ impl DiskCache {
pub fn set(&self, filename: &Path, data: &[u8]) -> std::io::Result<()> {
let path = self.location.join(filename);
match path.parent() {
- Some(ref parent) => fs::create_dir_all(parent),
+ Some(ref parent) => fs::create_dir_all(parent)
+ .map_err(|e| with_io_context(&e, format!("{:#?}", &path))),
None => Ok(()),
}?;
deno_fs::write_file(&path, data, 0o666)
+ .map_err(|e| with_io_context(&e, format!("{:#?}", &path)))
}
pub fn remove(&self, filename: &Path) -> std::io::Result<()> {