Skip to content

Map DirectoryNotFound to FileNotFound for open command (issue #10085)#10089

Merged
sholderbach merged 1 commit intonushell:mainfrom
GPadley:GP/file_only_for_open
Sep 21, 2023
Merged

Map DirectoryNotFound to FileNotFound for open command (issue #10085)#10089
sholderbach merged 1 commit intonushell:mainfrom
GPadley:GP/file_only_for_open

Conversation

@GPadley
Copy link
Copy Markdown
Contributor

@GPadley GPadley commented Aug 21, 2023

Description

This PR should close #10085
Maps DirectoryNotFound errors to FileNotFound. All other errors are left unchanged.

User-Facing Changes

This means a user will see FileNotFound instead of DirectoryNotFound which is more meaning full to the user.

Tests + Formatting

After Submitting

@GPadley GPadley changed the title Raise FileNotFound error instead of DirectoryNotFound error for open command (issue #10085) Replace DirectoryNotFound for FileNotFound for open command (issue #10085) Aug 21, 2023
Copy link
Copy Markdown
Member

@amtoine amtoine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've been able to see that this PR fixes the unhelpful error 👌

could we have a little test to make sure that open euwiqoeu gives a file not found error? 😋

@GPadley
Copy link
Copy Markdown
Contributor Author

GPadley commented Aug 22, 2023

could we have a little test to make sure that open euwiqoeu gives a file not found error? 😋

Looked into the tests and found one that was already testing this functionality, updated to check file not found is within the error message rather than general not found which was used before.

I'm new to Rust, is there a way to capture the actual error instead and assert it is of type nu_protocol::ShellError::FileNotFound? Probably is a little overkill, but is how I often do testing in Python.

Let me know if that fulfills the requirements you expect.

@GPadley GPadley requested a review from amtoine August 22, 2023 17:05
@amtoine
Copy link
Copy Markdown
Member

amtoine commented Aug 25, 2023

because

~ INSERT > open i_dont_exist.txt
Error: nu::shell::directory_not_found

  × Directory not found
   ╭─[entry #1:1:1]
 1  open i_dont_exist.txt
   ·      ────────┬───────
   ·              ╰── directory not found
   ╰────

should have file not found now, i think the change you made to the existing test is very nice 👌

@amtoine amtoine dismissed their stale review August 25, 2023 17:28

requested changes have been added

@amtoine
Copy link
Copy Markdown
Member

amtoine commented Aug 25, 2023

I'm new to Rust, is there a way to capture the actual error instead and assert it is of type nu_protocol::ShellError::FileNotFound? Probably is a little overkill, but is how I often do testing in Python.

not sure at all in that case 🤔

nu! is testing as if the test was in the REPL, so it does not see the ShellError::FileNotFound, but only the output as you'd do in the REPL, this is why actual.err is a string and not a ShellError and we need to use .contains on it.

@GPadley
Copy link
Copy Markdown
Contributor Author

GPadley commented Aug 26, 2023

@amtoine OOI what's the process for getting this reviewed and merged in? Is it done on a schedule or quite ad-hoc?

@amtoine
Copy link
Copy Markdown
Member

amtoine commented Aug 26, 2023

@amtoine OOI what's the process for getting this reviewed and merged in? Is it done on a schedule or quite ad-hoc?

there's no schedule to land PRs, only to release Nushell every 4 weeks 😋

this PR touches parts of the source base i'm not familiar with, so it might need another quick look from another member of the core team, but other than that, it looks it's in a good shape to land soon 😌

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your patience! This looks like a great first PR to nushell!

If you can resolve the merge conflict this should be good to go

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 9, 2023

@GPadley I think we're ready to land this if you can resolve the conflicts. Thanks!

@GPadley
Copy link
Copy Markdown
Contributor Author

GPadley commented Sep 16, 2023

Apologies for the delay - have fixed merge conflicts with main so should be ready to go once all check are passed.

@GPadley GPadley force-pushed the GP/file_only_for_open branch from b159668 to 74a810f Compare September 16, 2023 23:09
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Sep 17, 2023

After reviewing this again, it looks like we have 13 places where file_only is set to false and 1 place where it's set to true. I'm wondering if it would be better just to remove all the file_only bools and just change the error message to "file or directory not found"?

I'm not sure it's worth all these changes just to have it used in 1 place. What do others think?

@amtoine
Copy link
Copy Markdown
Member

amtoine commented Sep 17, 2023

After reviewing this again, it looks like we have 13 places where file_only is set to false and 1 place where it's set to true. I'm wondering if it would be better just to remove all the file_only bools and just change the error message to "file or directory not found"?

I'm not sure it's worth all these changes just to have it used in 1 place. What do others think?

sounds sensible to me to say "file or directory", this is what Bash is doing and it does the job, in the end, files and directories are mostly the same thing in the file system 😋

$ ls euqwio
ls: cannot access 'euqwio': No such file or directory
$ cd ewuqi
bash: cd: ewuqi: No such file or directory

@GPadley
Copy link
Copy Markdown
Contributor Author

GPadley commented Sep 17, 2023

So there are a couple ways I could do this:

  • Remove the DirectoryNotFound and FileNotFound error messages and only have a FileOrDirectoryNotFound error
  • Add a FileOrDirectoryNotFound error and update this single instance.
    What are people's opinions?

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am neither a fan of degrading the error message quality nor bloating the ShellError with rarely used variants, people will almost certainly pick the wrong one in the future.

@GPadley GPadley force-pushed the GP/file_only_for_open branch from 74a810f to b1109c3 Compare September 18, 2023 17:32
@GPadley GPadley changed the title Replace DirectoryNotFound for FileNotFound for open command (issue #10085) Map DirectoryNotFound to FileNotFound for open command (issue #10085) Sep 18, 2023
Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this error nicer for the users and iterating on this with us! Let's go!

@sholderbach sholderbach merged commit 1c677c9 into nushell:main Sep 21, 2023
@daniel-vainsencher
Copy link
Copy Markdown

@GPadley thank you! I had reported the linked issue, and its cool you fixed it :)

hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
…#10089)

# Description


This PR should close nushell#10085
Maps `DirectoryNotFound` errors to `FileNotFound`. All other errors are
left unchanged.

# User-Facing Changes

This means a user will see `FileNotFound` instead of `DirectoryNotFound`
which is more meaning full to the user.
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.

"open" reports nu::shell::directory_not_found, should report nu::shell::file_not_found

5 participants