Display path in error message when file create/write fails (#32036)

Using .unwrap() will panic and display the error; however, the path
isn't displayed which makes debugging harder.
This commit is contained in:
steviez 2023-06-12 11:45:26 -05:00 committed by GitHub
parent 0645e96bc6
commit 2e5b062809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 2 deletions

View File

@ -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;
}