Skip to content

Commit

Permalink
Display path in error message when file create/write fails (#32036)
Browse files Browse the repository at this point in the history
Using .unwrap() will panic and display the error; however, the path
isn't displayed which makes debugging harder.
  • Loading branch information
steviez authored Jun 12, 2023
1 parent 0645e96 commit 2e5b062
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions runtime/src/accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,28 @@ impl AccountHashesFile {
// we have hashes to write but no file yet, so create a file that will auto-delete on drop
self.count_and_writer = Some((
0,
BufWriter::new(tempfile_in(&self.dir_for_temp_cache_files).unwrap()),
BufWriter::new(
tempfile_in(&self.dir_for_temp_cache_files).unwrap_or_else(|err| {
panic!(
"Unable to create file within {}: {err}",
self.dir_for_temp_cache_files.display()
)
}),
),
));
}
let count_and_writer = self.count_and_writer.as_mut().unwrap();
assert_eq!(
std::mem::size_of::<Hash>(),
count_and_writer.1.write(hash.as_ref()).unwrap()
count_and_writer
.1
.write(hash.as_ref())
.unwrap_or_else(|err| {
panic!(
"Unable to write file within {}: {err}",
self.dir_for_temp_cache_files.display()
)
})
);
count_and_writer.0 += 1;
}
Expand Down

0 comments on commit 2e5b062

Please sign in to comment.