From 47c1f475bf3c8c0582d1f219ebe951d5540342ac Mon Sep 17 00:00:00 2001 From: nibon7 Date: Wed, 13 Jul 2022 20:00:30 +0800 Subject: [PATCH] Fix panic when opening symlink which points to an inaccessible directory (#6034) * Fix panic when opening symlink which points to an inaccessible directory Fixes #6027 Signed-off-by: nibon7 * tweak words Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> --- crates/nu-command/src/filesystem/open.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index 7e523f6d99..3bdc910873 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -88,14 +88,14 @@ impl Command for Open { if permission_denied(&path) { #[cfg(unix)] - let error_msg = format!( - "The permissions of {:o} do not allow access for this user", - path.metadata() - .expect("this shouldn't be called since we already know there is a dir") - .permissions() - .mode() - & 0o0777 - ); + let error_msg = match path.metadata() { + Ok(md) => format!( + "The permissions of {:o} does not allow access for this user", + md.permissions().mode() & 0o0777 + ), + Err(e) => e.to_string(), + }; + #[cfg(not(unix))] let error_msg = String::from("Permission denied"); Err(ShellError::GenericError(