Skip to content
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

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

cptpiepmatz
Copy link
Contributor

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 the nu_engine::glob_from function. It uses std::path::Path::canonicalize some layers down and that may return an std::io::Error. All these errors were handled as "directory not found" which will be translated to "file not found" in the open command. To fix this, I handled the PermssionDenied error kind of the io error and passed that down. Now trying to open a file from a directory with no permissions returns a "permission denied" error.

Before/After:
image

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

Copy link
Contributor

@132ikl 132ikl left a 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! 😄

Comment on lines +94 to +106
ShellError::GenericError {
error,
msg,
span: _,
help,
inner,
} if error.as_str() == "Permission denied" => ShellError::GenericError {
error,
msg,
span: Some(arg_span),
help,
inner,
},
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@cptpiepmatz cptpiepmatz requested a review from 132ikl December 30, 2024 22:44
@WindSoilder
Copy link
Collaborator

Sorry it takes a long time, would you resolve the conflict first?

@cptpiepmatz
Copy link
Contributor Author

Resolved it, let's wait for the pipeline.

@fdncred
Copy link
Collaborator

fdncred commented Jan 7, 2025

Are we ready to land this?

@132ikl
Copy link
Contributor

132ikl commented Jan 7, 2025

LGTM

@fdncred fdncred merged commit dc52a6f into nushell:main Jan 7, 2025
15 checks passed
@fdncred
Copy link
Collaborator

fdncred commented Jan 7, 2025

Thanks!

@github-actions github-actions bot added this to the v0.102.0 milestone Jan 7, 2025
@cptpiepmatz cptpiepmatz deleted the fix-open-read-dir-perm branch January 8, 2025 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error file_not_found in Windows when missing read permission
4 participants