From f5950196d9ab73f338bb617dd3041d4bbc833e1c Mon Sep 17 00:00:00 2001 From: dnaq Date: Sun, 28 Jul 2024 18:29:26 +0200 Subject: [PATCH] Fix panic when starting helix tutor (#11352) Closes #11351 Also fixed some minor issues related to log message contents, and removed unnecessary use of `.as_mut()` as per code review comments on the PR. --- helix-view/src/document.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 885f33e8a..d470826e7 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1080,22 +1080,25 @@ impl Document { } pub fn pickup_last_saved_time(&mut self) { - self.last_saved_time = match self.path.as_mut().unwrap().metadata() { - Ok(metadata) => match metadata.modified() { - Ok(mtime) => mtime, - Err(_) => { + self.last_saved_time = match self.path().as_mut() { + Some(path) => match path.metadata() { + Ok(metadata) => match metadata.modified() { + Ok(mtime) => mtime, + Err(_) => { + log::error!( + "Use a system time instead of fs' mtime not supported on this platform" + ); + SystemTime::now() + } + }, + Err(e) => { log::error!( - "Use a system time instead of fs' mtime not supported on this platform" + "Use a system time instead of fs' mtime: failed to file's metadata: {e}" ); SystemTime::now() } }, - Err(e) => { - log::error!( - "Use a system time instead of fs' mtime: failed to file's metadata: {e}" - ); - SystemTime::now() - } + None => SystemTime::now(), }; }