Skip to content

ls: Add NotADirectory message#11341

Closed
danielzgtg wants to merge 1 commit intouutils:mainfrom
danielzgtg:feat/lsNotADirectoryMessage
Closed

ls: Add NotADirectory message#11341
danielzgtg wants to merge 1 commit intouutils:mainfrom
danielzgtg:feat/lsNotADirectoryMessage

Conversation

@danielzgtg
Copy link
Copy Markdown
Contributor

This makes the error message for ls ~/.bashrc/test less scary. Two people had already complained about the phrasing "unknown io error".

Before

Some say the error message is scarier than the GNU coreutils one.

home@daniel-desktop3:~$ /bin/ls .bashrc/test
/bin/ls: unknown io error: '.bashrc/test', 'Os { code: 20, kind: NotADirectory, message: "Not a directory" }'
home@daniel-desktop3:~$ /bin/gnuls .bashrc/test
/bin/gnuls: cannot access '.bashrc/test': Not a directory

After

I got rid of the word "unknown". I changed the phrasing, because Peter Cordes said "it hasn't checked which path component isn't a directory; it's not the final one".

$ /usr/bin/cargo run --color=always --bin ls --profile dev --manifest-path /home/home/CLionProjects/uutils/src/uu/ls/Cargo.toml -- /home/home/.bashrc/test
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/ls /home/home/.bashrc/test`
ls: '/home/home/.bashrc/test': A path component was not a directory

Process finished with exit code 2

@xtqqczze
Copy link
Copy Markdown
Contributor

We also need a French translation in src/uu/ls/locales/fr-FR.ftl

@sylvestre
Copy link
Copy Markdown
Contributor

i can take care of the french translation
but could you please add a test to verify this error message, thanks

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/tail/retry. tests/tail/retry is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/cp/sparse-extents is now being skipped but was previously passing.

@danielzgtg danielzgtg force-pushed the feat/lsNotADirectoryMessage branch from f445acd to 790634f Compare March 15, 2026 22:27
@danielzgtg
Copy link
Copy Markdown
Contributor Author

but could you please add a test to verify this error message, thanks

Added:

#[test]
#[cfg(unix)]
fn test_ls_not_a_directory_errors() {
    let scene = TestScenario::new(util_name!());
    scene
        .ucmd()
        .arg("/etc/hosts/test")
        .fails()
        .code_is(2)
        .stderr_contains("not a directory");
}

@sylvestre
Copy link
Copy Markdown
Contributor

@danielzgtg
Copy link
Copy Markdown
Contributor Author

danielzgtg commented Mar 15, 2026

dupe of https://github.com/uutils/coreutils/pull/11333/changes ?

Same bug. However, the advantages of my PR are:

  • The error message is not misleading
  • My test uses /etc/hosts, which is compatible with macOS and Android. That PR uses /sbin/init, which only works on desktop Unix/Linux

However, I don't care if my PR gets closed and the other gets merged because I'm used to the 1st point, and I don't program on the platforms in the 2nd point.

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/retry is no longer failing!
Congrats! The gnu test tests/expand/bounded-memory is now passing!

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented Mar 16, 2026

Better message is one of at aim of this project. But, "A path component was" would add sed hack for GnuTests in the future. Do you consider suggesting the change to GNU too?

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented Mar 16, 2026

The message is coming from OS. Different might cause other issue at different command.

@danielzgtg
Copy link
Copy Markdown
Contributor Author

Closing as I don't know how complex is "sed hack for GnuTests in the future."

@danielzgtg danielzgtg closed this Mar 16, 2026
@sylvestre
Copy link
Copy Markdown
Contributor

Closing as I don't know how complex is "sed hack for GnuTests in the future."

it is trivial.
see: https://github.com/Ecordonnier/coreutils/blob/d6c793c09abb43078ef6ecff6b8f49eccb0cc015/util/build-gnu.sh#L342

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.

4 participants