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

more handle errors with multiple files #4997

Merged
merged 6 commits into from
Feb 4, 2024
Merged

more handle errors with multiple files #4997

merged 6 commits into from
Feb 4, 2024

Conversation

Ludmuterol
Copy link
Contributor

@Ludmuterol Ludmuterol commented Jun 22, 2023

added handling for case mentioned in (#4906) and added some tests as well.
But i have to say i stumbled upon something i need to ask about: is there a reason the more function returns an error with an exit code? cause when i compare:

~/Desktop/coreutils/target/debug$ ./coreutils more nonexistent_file
more: cannot open 'nonexistent_file': No such file or directory
~/Desktop/coreutils/target/debug$ echo $?
1
~/Desktop/coreutils/target/debug$ more nonexistent_file
more: cannot open nonexistent_file: No such file or directory
~/Desktop/coreutils/target/debug$ echo $?
0

is that an issue or smth that that doesn't need to be changed?
i tried to keep it this way but if multiple files are given it will always return no error. is this okay? or how should more handle one file failing and one working?

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail-2/inotify-dir-recreate

@cakebaker cakebaker linked an issue Jun 23, 2023 that may be closed by this pull request
src/uu/more/src/more.rs Outdated Show resolved Hide resolved
Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

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

Hi! I've been a little absent from this project for a while, so that's why I didn't see this sooner.

I like the idea here! We should definitely improve this case.

If I try this patch, I get the following:

::::::::::::::
oranda.json
::::::::::::::
more: 'src' is a directory.
::::::::::::::
oranda.json
::::::::::::::
{
  "project": {
    "name": "uutils coreutils"
...

That seems a bit strange and like there's something going on with the printing. I've made a comment with some functions that might help here.

less and util-linux more both print the error message and then wait for user input. This makes sense because the next file might obscure the message. However, for a first version we don't have to do that yet.

But i have to say i stumbled upon something i need to ask about: is there a reason the more function returns an error with an exit code?

Nope, it'd be great if you could fix that! Thanks for finding that!

1,
format!("{} is a directory.", file.quote()),
));
if length == 1 {
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to suggest using the show! and map_err_context functionality:

I think those would make it unnecessary to check the number of files and to log the error messages in the buffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well i was using the buffer so that i dont have to switch the raw mode for each message.. do i even have to do that, since the errormessages are printed to stderr and not stdout? sadly the documentation for the raw mode doesnt mention stderr..
(https://docs.rs/crossterm/0.27.0/crossterm/terminal/index.html#raw-mode)

@Ludmuterol
Copy link
Contributor Author

my terminal currently gives me the broken output i associate with the raw mode not being disabled. but i cant seem to find where the program could exit without disabling it first. and every test case i tried doesnt replicate the terminal not disabling the raw mode. that cargo test doesnt seem to execute the tests in a predictable order doesnt help with finding the case that leaves the terminal in raw mode... any keywords/ideas on how i can find the reason for that?

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate

format!("cannot open {}: No such file or directory", file.quote()),
));
terminal::enable_raw_mode().unwrap();
continue;
}
let opened_file = match File::open(file) {
Err(why) => {
terminal::disable_raw_mode().unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

I don't actually know why it stays in raw mode, but it seems unrelated to this change, so let's merge it!

@tertsdiepraam tertsdiepraam merged commit 96d96e7 into uutils:main Feb 4, 2024
54 of 57 checks passed
ysthakur pushed a commit to ysthakur/coreutils that referenced this pull request Feb 27, 2024
* more handle errors with multiple files

* tests/more test refactor and new case

* tests/more new cases

* more: use show! and change exitstatus and adjust tests to new exitvalue

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
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.

more: incomplete error handling for multiple file input
3 participants