-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle permission denied error at nu_engine::glob_from
#14679
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one has been bugging me for a long time, thanks! 😄
ShellError::GenericError { | ||
error, | ||
msg, | ||
span: _, | ||
help, | ||
inner, | ||
} if error.as_str() == "Permission denied" => ShellError::GenericError { | ||
error, | ||
msg, | ||
span: Some(arg_span), | ||
help, | ||
inner, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment explaining why this is here? It makes sense in the context of the PR, but I think this might be a bit confusing if you were to stumble across it.
Ok(p) => p, | ||
Err(err) => { | ||
return match err.kind() { | ||
ErrorKind::PermissionDenied => Err(ShellError::GenericError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a ShellError::IOError
instead of a ShellError::GenericError
; cd
uses IOError
when you attempt to cd
into a directory without permission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since ShellError::IOError
doesn't contain an easy reliable way to check which io error is used, I don't like using it. And adding std::io::ErrorKind
to ShellError::IOError
which would be optimal, kind of explodes the scope here imo.
Sorry it takes a long time, would you resolve the conflict first? |
Resolved it, let's wait for the pipeline. |
Are we ready to land this? |
LGTM |
Thanks! |
Description
#14528 mentioned that trying to
open
a file in a directory where you don't have read access results in a "file not found" error. I investigated the error and could find the root issue in thenu_engine::glob_from
function. It usesstd::path::Path::canonicalize
some layers down and that may return anstd::io::Error
. All these errors were handled as "directory not found" which will be translated to "file not found" in theopen
command. To fix this, I handled thePermssionDenied
error kind of the io error and passed that down. Now trying toopen
a file from a directory with no permissions returns a "permission denied" error.Before/After:
User-Facing Changes
That error is fixed, so correct error message.
Tests + Formatting
toolkit fmt
toolkit clippy
toolkit test
toolkit test stdlib
After Submitting
fixes #14528