Skip to content

Commit 177e492

Browse files
committed
melib/maildir: log error instead of debug_assert!
In MaildirFilePathExt::to_envelope_hash(), don't panic if path is not a regular file. The watching code might attempt to calculate the hash of a file that has been removed by others. Log error instead in the debug log level. Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent 55d9bb8 commit 177e492

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

melib/src/maildir/utilities.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,31 @@ impl MaildirFilePathExt for Path {
451451
}
452452

453453
fn to_envelope_hash(&self) -> EnvelopeHash {
454-
debug_assert!(self.is_file());
454+
#[cfg(debug_assertions)]
455+
{
456+
if !matches!(self.try_exists(), Ok(true)) {
457+
log::debug!(
458+
"{}",
459+
Error::new("Path does not exist")
460+
.set_summary(format!(
461+
"Message with path {} does not exist.",
462+
self.display()
463+
))
464+
.set_kind(ErrorKind::NotFound)
465+
);
466+
}
467+
if !self.is_file() {
468+
log::debug!(
469+
"{}",
470+
Error::new("Path is not a file")
471+
.set_summary(format!(
472+
"Message with path {} is not a file.",
473+
self.display()
474+
))
475+
.set_kind(ErrorKind::ValueError)
476+
);
477+
}
478+
}
455479
let mut hasher = DefaultHasher::default();
456480
self.hash(&mut hasher);
457481
EnvelopeHash(hasher.finish())

0 commit comments

Comments
 (0)