Skip to content

Commit

Permalink
fix: graceful error handling for grit check in uninitialized contex…
Browse files Browse the repository at this point in the history
…ts (#61)
  • Loading branch information
mparker3 authored Mar 23, 2024
1 parent cf59ebf commit ff58de2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/gritcache/src/new_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl ThreadedCache {
};

let (sender, receiver) = mpsc::channel::<HashKey>();
let mut writer = Self::new_writer(&mismatches_path)?;
let manager = thread::spawn(move || {
let mut writer = Self::new_writer(&mismatches_path).unwrap();
while let Ok(key) = receiver.recv() {
writer.write_all(&key).unwrap();
}
Expand Down Expand Up @@ -105,7 +105,8 @@ impl ThreadedCache {
.create(true)
.append(true)
.open(path)
.context("Failed to open cache file".to_string())?,
.context("Failed to open cache file".to_string())
.context("Please run `grit init` or set GRIT_CACHE_DIR to cache check results")?,
);

Ok(writer)
Expand Down Expand Up @@ -172,6 +173,7 @@ mod tests {

let path = PathBuf::from(".");
let mismatches_cache_path = path.join(MISMATCHES_CACHE_NAME);
let bad_path = PathBuf::from("./doesnotexist").join(MISMATCHES_CACHE_NAME);

println!(
"mismatches_cache_path: {}",
Expand All @@ -183,6 +185,9 @@ mod tests {
std::fs::remove_file(&mismatches_cache_path)?;
}

// assert cache creation fails gracefully on invalid paths
assert!(ThreadedCache::new(bad_path.clone(), false).await.is_err());

// Create an empty cache
let (cache, manager) = ThreadedCache::new(path.clone(), true).await?;

Expand Down

0 comments on commit ff58de2

Please sign in to comment.